@carbon/type

中文文档
11.71.0发布于 2026/11/04Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 81.6万

Typography for digital and software products using the Carbon Design System

原始使用文档
文档目录12 节
  1. Getting started
  2. Usage
  3. Type styles
  4. Type classes
  5. Font family
  6. Reset
  7. Replacing the typeface
  8. Type scale
  9. 📚 Examples
  10. 🙌 Contributing
  11. 📝 License
  12. IBM Telemetry

@carbon/type

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:

FeatureDescription
Font faceInclude IBM Plex™ font faces in your application. Uses Akamai CDN
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)

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.

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:

@use '@carbon/type';

@include type.type-style('token-name');

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:

@use '@carbon/type';

@include type.type-style('token-name', true);

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:

@use '@carbon/type';

:root {
  @include type.type-classes();
}

And then add the appropriate classes to the element you want to style

<span className="cds--type-mono">Test sentence</span>
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:

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

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

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

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

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

Reset

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

@use '@carbon/type';

:root {
  @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.

Replacing the typeface

@carbon/type can configure the font families used by its own Sass APIs, but it does not generate Carbon component styles or control IBM Plex @font-face output. Carbon's type foundation and component styles are closely integrated, so application-wide typeface replacement must be configured through the @carbon/styles Sass entrypoint. See Replacing the typeface in @carbon/styles.

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:

@use '@carbon/type';

.my-selector {
  @include type.type-scale(4);
}

📚 Examples

If you're looking for more examples on how to use @carbon/type, we have some examples that you can check out:

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! 👀

📝 License

Licensed under the Apache 2.0 License.

IBM Telemetry IBM Telemetry

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.

版本与发布记录

@carbon/type 共发布 344 个版本,首次发布于 2018/11/10;过去 12 个月发布了 47 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
11.71.0latest2026/11/044 天前
11.71.0-rc.02026/11/035 天前
12.0.0-alpha.4v12-alpha2026/10/2812 天前
12.0.0-alpha.32026/10/2118 天前
11.70.02026/10/2119 天前
11.70.0-rc.02026/10/2020 天前

其他发布通道:alpha → 0.0.1-alpha.32,beta → 0.0.1-beta.5,canary → 10.6.0-alpha.5708,nightly → 10.19.0-alpha.0,v10-next → 10.45.6,v12-alpha → 12.0.0-alpha.4。

关于 @carbon/type 的常见问题

@carbon/type 是什么?

Typography for digital and software products using the Carbon Design System

如何安装 @carbon/type?

在项目目录运行 npm install @carbon/type,或使用 pnpm add / yarn add / bun add。

@carbon/type 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@carbon/type 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@carbon/type 可以商用吗?

@carbon/type 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@carbon/type 的下载量有多少?

根据 npm 官方下载统计,@carbon/type 在 2026/10/09 – 2026/11/07 这 30 天内被下载 815,651 次,日均约 27,188 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@carbon/type 还在维护吗?

最新版本 11.71.0 发布于 2026/11/04(4 天前);至今共发布 344 个版本,其中过去 12 个月发布了 47 个;首次发布于 2018/11/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。