Skip to main contentCarbon Design System

Typography

Type is a core part of any offering and critical to how brands express and communicate throughout any experience. Use the Carbon type package to leverage IBM Plex and create effective typography across your products more easily.

If you’re using carbon-components there’s no reason to install the type package separately. See our get started guide to start building.

Get 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:

FeatureDescription
Font faceInclude IBM Plex™ font faces in your application. Uses Google fonts
Type classesHelpers to use type styles directly. Not included by default
Font familyDefines the font stack for IBM Plex™ in your application, provides helpers for working with font definitions
ResetProvides a high-level CSS Reset to use in your project
ScaleProvides the type scale. Can access the size at any given step (step 1, 2, 3, etc)
StylesProvides type styles for your application (heading-01, body-long-01, etc)

To include @carbon/type in your project, you can write the following in your Sass file:

@import '@carbon/type/scss/type';
@import '@carbon/type/scss/font-face/mono';
@import '@carbon/type/scss/font-face/sans';
@include type-reset();
@include font-face-mono();
@include font-face-sans();

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:

@import '@carbon/elements/scss/type/path-to-import';

For example:

@import '@carbon/elements/scss/type/styles';

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:

{
loader: 'sass-loader',
options: {
includePaths: ['node_modules'],
},
}

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.

You can find a full reference of the type styles that are available on the Carbon Design System website .

You can include a token in your Sass file by writing:

@import '@carbon/type/scss/styles';
@include type-style('productive-heading-01');

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:

@import '@carbon/type/scss/styles';
@include type-style('token-name', true);

Font-face

@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:

@import '@carbon/type/scss/font-face/mono';
@include font-face-mono();

Similarly, you can include IBM Plex Sans and IBM Plex Serif by writing:

@import '@carbon/type/scss/font-face/mono';
@import '@carbon/type/scss/font-face/sans';
@import '@carbon/type/scss/font-face/serif';
@include font-face-mono();
@include font-face-sans();
@include font-face-serif();

Type classes

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';
SelectorDescription
.cds--type-monoSpecify the font face as IBM Plex Mono
.cds--type-sansSpecify the font face as IBM Plex Sans
.cds--type-serifSpecify the font face as IBM Plex Serif
.cds--type-lightSpecify the font weight as light (300)
.cds--type-regularSpecify the font weight as regular (400)
.cds--type-semiboldSpecify the font weight as semibold (600)
.cds--type-italicSpecify the font style as italic
.cds--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 $font-families variable. You can also access a specific font family by using the font-family function by doing:

.my-selector {
font-family: font-family('mono');
}

You can also use the font-family mixin to automatically set the font-family property for you:

.my-selector {
@include font-family('mono');
}

You can see all the available font families in $font-families .

Reset

An optional type reset is provided under the type-reset mixin. You can include this mixin by writing the following in your Sass file:

@import '@carbon/type/scss/reset';
@include type-reset();

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:

@import '@carbon/type/scss/scale';

You can access a specific step in the type scale by using the type-scale function:

@import '@carbon/type/scss/scale';
.my-selector {
font-size: type-scale(1);
}

There is also a type-scale mixin that will set font-size for your directly:

@import '@carbon/type/scss/scale';
.my-selector {
@include type-scale(1);
}

Resources