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:
Provides type styles for your application (heading-01, body-long-01, etc)
The @carbon/type package enables you to use typography from the IBM Design
Language, including the type scale and fonts, along with typography design
tokens from the Carbon Design System. It also comes with opinionated defaults
for type styles on common elements like h1, h2, p, etc.
You can use this package by writing the following:
@use'@carbon/type';
// Include type reset@include type.reset();
// Include default type styles, targets h1, h2, h3, etc@include type.default-type();
// Include utility classes for type-related properties@include type.type-classes();
.selector {
// Include a type style@include type.type-style('productive-heading-01');
}
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/react, the import paths become:
@use'@carbon/react/scss/type';
Type styles
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 type-style to enable fluid styles. For
example:
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:
@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:
@use'@carbon/type';
The font stacks are available under the $font-families variable. You can also
access a specific font family by using the 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 $type-scale variable and corresponding
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:
@use'@carbon/type';
You can access a specific step in the type scale by using the type-scale
function:
.my-selector {
font-size: type.type-scale(1);
}
There is also a type-scale mixin that will set font-size for your directly:
You can also see more documentation regarding the available tokens
here
🙌 Contributing
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 de-identified and anonymized 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
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 13 open source maintainers collaborating on the project.
Package last updated on 24 Oct 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.