@carbon/themes

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

Themes for applying color in the Carbon Design System

原始使用文档
文档目录11 节
  1. Getting started
  2. Usage
  3. Sass
  4. JavaScript
  5. Component tokens
  6. Modifying token values
  7. 📖 API Documentation
  8. 📚 Examples
  9. 🙌 Contributing
  10. 📝 License
  11. IBM Telemetry

@carbon/themes

Themes for applying color in the Carbon Design System

Getting started

To install @carbon/themes in your project, you will need to run the following command using npm:

npm install -S @carbon/themes

If you prefer Yarn, use the following command instead:

yarn add @carbon/themes

Usage

You can use @carbon/themes in JavaScript or Sass by including this package in your project. By default, @carbon/themes provides a set of color tokens that are pre-defined for a specific theme. Currently, we offer the following color themes: white, gray 10, gray 90, gray 100 .

You can preview all of the token values for this on the Carbon Design System website.

Sass

If your project is using Sass, you can include this package and the corresponding default theme by writing the following in your Sass file:

@use '@carbon/themes/scss/themes';

By default, the white theme will be initialized. If you would like to include another theme, you can do so by setting the global theme variable in the import. For example:

@use '@carbon/themes/scss/themes' as *;
@use '@carbon/themes' with (
  $theme: $g100
);

Inline theming can be done by using the mixin. For example:

@use '@carbon/themes/scss/themes';
@use '@carbon/themes/scss/theme';

// Uses the default white theme here

.my-dark-theme {
  @include theme.theme(themes.$g90);
}

.my-darker-theme {
  @include theme.theme(themes.$g100);
}

JavaScript

If you're looking to use these themes in JavaScript, we export a variety of bindings for you to use, including:

import {
  // An object of all themes
  themes,

  // Direct theme values
  white,
  g10,
  g90,
  g100,

  // Specific token values
  background,
  interactive,
  textPrimary,
} from '@carbon/themes';

Component tokens

The DTCG migration introduced per-component token sets. They are exported as named objects:

Breaking change (11.78.0): Prior to 11.78.0 these objects were double-nested (e.g. buttonTokens.buttonTokens). The repeated property is now undefined — drop it to get the flat object directly.

import {
  buttonTokens,
  tagTokens,
  notificationTokens,
  statusTokens,
  contentSwitcherTokens,
} from '@carbon/themes';

Each object contains the token values for all four themes. The corresponding Sass output is available via @use '@carbon/themes/scss/component-tokens'.

Modifying token values

Token values are defined in tokens/themes/ using the DTCG 2025.10 token format. Each theme has a folder with a theme.tokens.json file (theme tokens) and one <component>.tokens.json file per component (component tokens). These are the single source of truth — do not edit generated files directly. See tokens/README.md for the format.

To add or update a token:

  1. Edit the token in tokens/themes/<theme>/theme.tokens.json (or the relevant <component>.tokens.json file for component tokens) for every theme
  2. Run yarn build in this package to regenerate all outputs
  3. Run yarn test --testPathPatterns=packages/themes from the repo root to confirm nothing regressed

📖 API Documentation

If you're looking for @carbon/themes API documentation, check out:

📚 Examples

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

🙌 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/themes 共发布 380 个版本,首次发布于 2019/01/11;过去 12 个月发布了 52 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
11.85.0latest2026/11/044 天前
11.85.0-rc.02026/11/035 天前
12.0.0-alpha.5v12-alpha2026/10/2812 天前
12.0.0-alpha.42026/10/2118 天前
11.84.02026/10/2119 天前
11.84.0-rc.02026/10/2020 天前

其他发布通道:alpha → 0.0.1-alpha.32,beta → 0.0.1-beta.5,canary → 10.7.0-alpha.5727,nightly → 10.25.0-alpha.0,v10-next → 10.55.6,v12-alpha → 12.0.0-alpha.5。

关于 @carbon/themes 的常见问题

@carbon/themes 是什么?

Themes for applying color in the Carbon Design System

如何安装 @carbon/themes?

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

@carbon/themes 支持 TypeScript 吗?

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

@carbon/themes 支持 ESM 还是 CommonJS?

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

@carbon/themes 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@carbon/themes 可以商用吗?

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

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

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

@carbon/themes 还在维护吗?

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