@18f/identity-design-system

中文文档
9.8.0发布于 2026/08/22CC0-1.0TypeScriptESM + CJS近 30 天下载 9484

The global style of Login.gov

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. Styles
  4. JavaScript
  5. Options
  6. Optimization
  7. Theme Variables
  8. License

Login.gov Design System

The Login.gov Design System is an extension of the U.S. Web Design System used on Login.gov sites to consistently identify the Login.gov brand.

This documentation describes how to use the Login.gov Design System in a new project. Read CONTRIBUTING.md to learn more about contributing to the design system itself.

Installation

Node.js is required to use the Login.gov Design System. You should install this first if it's not already available.

Next, install the package using NPM from your project's directory:

npm install @18f/identity-design-system

Usage

As an extension of the U.S. Web Design System (USWDS), the Getting started for developers guide can be a useful resource. The Login.gov Design System aims to be a drop-in replacement for the USWDS, so that all of its documentation would apply for the Login.gov Design System. The only change you're required to make is to update any references of @uswds/uswds with @18f/identity-design-system.

Styles

The Login.gov Design System uses Sass to generate stylesheets. While you can use any Sass compilation process, we recommend @18f/identity-build-sass, since it supports any environment where Node.js is already available, and it comes prebundled with default behaviors which are well-suited for the design system.

Here's an example stylesheet that imports the design system:

@use 'uswds-core';
@forward 'uswds';

The only requirements for Sass compilation are:

  • Your Sass load paths must include node_modules/@18f/identity-design-system/packages
  • You must be using the Dart Sass implementation of Sass

If you're using @18f/identity-build-sass, the following command will compile a CSS file to build/styles.css:

npx build-sass path/to/styles.css.scss --out-dir=build

Browser-Ready CSS Bundles

While it's recommended to import the Login.gov Design System as a Sass module to support optimization options, a precompiled CSS bundle is made available for convenience or for projects where it's not possible to include a Sass build process.

These files are found within dist/assets/css of the published NPM package. When installed locally, this is found at node_modules/@18f/identity-design-system.

<html>
  <head>
    <!-- ... -->
    <link rel="stylesheet" href="/path/to/identity-design-system/dist/assets/css/styles.css">
  </head>
  <body>
    <!-- ... -->
  </body>
</html>

JavaScript

As an NPM package, you can import the Login.gov Design System anywhere in your projects imports:

import '@18f/identity-design-system';

By default, this will include JavaScript for every component, which can increase load times for users and build times for developers. Refer to the Options section below to learn how to optimize JavaScript imports.

Browser-Ready JavaScript Bundles

While it's recommended to import the Login.gov Design System as an NPM package to support optimization options, a precompiled JavaScript bundle is made available for convenience or for projects where it's not possible to include a JavaScript build process.

These files are found within dist/assets/js of the published NPM package. When installed locally, this is found at node_modules/@18f/identity-design-system.

<html>
  <head>
    <!-- ... -->
    <script src="/path/to/identity-design-system/dist/assets/js/init.js"></script>
  </head>
  <body>
    <!-- ... -->
    <script src="/path/to/identity-design-system/dist/assets/js/main.js"></script>
  </body>
</html>

Options

Optimization

If your project is not using every component of the design system, it is recommended that you optimize your build by cherry-picking the individual components that you are using.

In Sass, you can do this by replacing the forwarded 'uswds' module with the packages of the individual components:

@use 'uswds-core';
- @forward 'uswds';
+ @forward 'usa-accordion';

You can find the package name on each component's documentation (e.g. Accordion → Package).

In JavaScript, you can import named members of the JavaScript package. If you are using a bundler which supports dead code elimination, any unused components will be removed from the compiled output. Each named import includes a on method to initialize the component on the page.

- import '@18f/identity-design-system';
+ import { accordion } from '@18f/identity-design-system';
+ accordion.on();

Theme Variables

The Login.gov Design System configures USWDS theme variables to provide defaults designed to be used across all Login.gov sites. These should almost always work well out-of-the-box, and not require further configuration.

If needed, you can extend these using the documented process for configuring settings, providing variables when importing the uswds-core package:

- @use 'uswds-core';
+ @use 'uswds-core' with (
+   $theme-body-font-size: 'sm'
+ );

License

See LICENSE for licensing information.

版本与发布记录

@18f/identity-design-system 共发布 22 个版本,首次发布于 2023/04/21;过去 12 个月发布了 5 个版本。

版本发布日期距今
9.8.0latest2026/08/222 个月前
9.7.02026/08/132 个月前
9.6.02026/08/063 个月前
9.5.12026/07/313 个月前
9.5.02026/07/313 个月前
9.4.02024/10/312 年前

其他发布通道:beta → 9.0.0-beta.2。

关于 @18f/identity-design-system 的常见问题

@18f/identity-design-system 是什么?

The global style of Login.gov

如何安装 @18f/identity-design-system?

在项目目录运行 npm install @18f/identity-design-system,或使用 pnpm add / yarn add / bun add。

@18f/identity-design-system 支持 TypeScript 吗?

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

@18f/identity-design-system 支持 ESM 还是 CommonJS?

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

@18f/identity-design-system 需要什么版本的 Node.js?

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

@18f/identity-design-system 可以商用吗?

@18f/identity-design-system 使用 CC0-1.0 许可。作者放弃著作权,可不受限制地使用。以上为概括,不构成法律意见,请以许可原文为准。

@18f/identity-design-system 的下载量有多少?

根据 npm 官方下载统计,@18f/identity-design-system 在 2026/10/05 – 2026/11/03 这 30 天内被下载 9,484 次,日均约 316 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@18f/identity-design-system 还在维护吗?

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