Typography for digital and software products using the Carbon Design System
Getting started
To install @carbon/type in your project, you will need to run the following
command using npm:
npm install -S @carbon/type
If you prefer Yarn, use the following command
instead:
yarn add @carbon/type
Usage
@carbon/type provides a variety of ways to work with typography from the IBM
Design Language. You can use all of these features either in JavaScript or Sass.
These features include:
This should include the default type reset from the project, in addition to
font-face definitions for IBM Plex Mono and IBM Plex Sans that come from Google
Fonts.
If you are using @carbon/elements, the import paths become:
In addition, you will need to setup node-sass so that node_modules is
included in the includePaths option. Often times, the tool that you are using
to build Sass files in your project should expose this option for you to set.
For example, if you are using Webpack you would use node-sass and
sass-loader with the following configuration for includePaths:
Instead of using a type scale, @carbon/type provides tokens that represent
what we call type styles. These tokens have a variety of properties for styling
how text is rendered on a page.
In addition, if the type style you are using has a fluid style then you can pass
in true as the second argument to carbon--type-style to enable fluid styles.
For example:
@carbon/type supports three font-face definitions that you can use to add IBM
Plex to your project. These font-face definitions include support for:
IBM Plex Mono
IBM Plex Sans
IBM Plex Serif
For most projects, only IBM Plex Mono and IBM Plex Sans is necessary. We also
provide IBM Plex Serif if you are building an editorial or marketing project.
These font-face definitions are pulling the above fonts from Google Fonts. As a
result, they are not intended to be used as a production asset for your project.
While you can depend on these for bootstrapping your project, we highly
recommend using the fonts from the @ibm/plex package and hosting them on a
global CDN.
You can include each font-face definition by including the corresponding file
and calling its mixin. For example, if you wanted to include IBM Plex Mono in
your project you would write the following in your Sass file:
The recommended way to style your application will be to use our
type styles. However, we also offer helper CSS classes for
specific use-cases. These are also helpful when quickly prototyping a project.
You can include type classes in your project by writing the following in your
Sass file:
@import'@carbon/type/scss/classes';
Selector
Description
.bx--type-mono
Specify the font face as IBM Plex Mono
.bx--type-sans
Specify the font face as IBM Plex Sans
.bx--type-serif
Specify the font face as IBM Plex Serif
.bx--type-light
Specify the font weight as light (300)
.bx--type-regular
Specify the font weight as regular (400)
.bx--type-semibold
Specify the font weight as semibold (600)
.bx--type-italic
Specify the font style as italic
.bx--type-<type-style>
Set styles for the given type style
Font family
@carbon/type provides the font stacks for all the IBM Plex fonts available.
You can access the font family information by including the following import in
your Sass file:
@import'@carbon/type/scss/font-family';
The font stacks are available under the $carbon--font-families variable. You
can also access a specific font family by using the carbon--font-family
function by doing:
This reset sets some top-level properties on html and body, namely
font-size, font-family, and some text-rendering options. We also map the
strong tag to the semibold font weight.
Type scale
A type scale is provided through the $carbon--type-scale variable and
corresponding carbon--type-scale function and mixin. However, for specifying
type styles, the recommendation is to use type styles .
If you are looking to use the type scale, you can include all the scale-related
utilities and variables by writing the following in your Sass file:
@import'@carbon/type/scss/scale';
You can access a specific step in the type scale by using the
carbon--type-scale function:
We're always looking for contributors to help us fix bugs, build new features,
or help us improve the project documentation. If you're interested, definitely
check out our Contributing Guide! 👀
This package uses IBM Telemetry to collect metrics data. By installing this
package as a dependency you are agreeing to telemetry collection. To opt out,
see
Opting out of IBM Telemetry data collection.
For more information on the data being collected, please see the
IBM Telemetry documentation.
Typography for digital and software products using the Carbon Design System
The npm package @carbon/type receives a total of 76,709 weekly downloads. As such, @carbon/type popularity was classified as popular.
We found that @carbon/type demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 0 open source maintainers collaborating on the project.
Package last updated on 11 Mar 2024
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.