Getting Started
This guide walks you through setting up and using the U.S. Web Design System (USWDS) in your project. Follow these steps to quickly integrate accessible, mobile-friendly components.
Installation
Install USWDS using your preferred package manager:
Using npm
npm install @uswds/uswds --save
Using yarn
yarn add @uswds/uswds
Using the CDN
For quick prototyping, you can include USWDS directly from the CDN:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@uswds/uswds@3.8.0/dist/css/uswds.min.css">
<script src="https://cdn.jsdelivr.net/npm/@uswds/uswds@3.8.0/dist/js/uswds.min.js"></script>
Prerequisites
USWDS requires Node.js version 18 or higher. Check your version with node --version.
Quick Start
After installation, create a basic HTML file to verify everything is working:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My USWDS Project</title>
<link rel="stylesheet" href="./path/to/uswds.min.css">
</head>
<body>
<h1>Hello, USWDS!</h1>
<button class="usa-button">Click me</button>
<script src="./path/to/uswds.min.js"></script>
</body>
</html>
Configuration
USWDS can be customized through its settings files. These files let you adjust colors, spacing, fonts, and component behavior.
Basic Configuration
Create a uswds-settings.scss file in your project:
// Override USWDS default settings
@uswds-overrides (
$theme-body-font-family: "Source Sans Pro", sans-serif,
$theme-heading-font-family: "Merriweather", serif,
$theme-primary-color: "blue",
$theme-site-max-width: "desktop",
$theme-site-alert-height: "auto",
);
| Setting | Default | Description |
|---|---|---|
$theme-body-font-family |
"Source Sans Pro" | Primary body font family |
$theme-heading-font-family |
"Merriweather" | Heading font family |
$theme-primary-color |
"blue" | Primary theme color |
$theme-site-max-width |
"desktop" | Maximum site width breakpoint |
Advanced Configuration
For advanced customization, you can modify the component-level settings:
// Component-specific overrides
@uswds-overrides (
// Button settings
$theme-button-font-family: "Source Sans Pro",
$theme-button-primary-font-color: "white",
// Card settings
$theme-card-background-color: "white",
$theme-card-border-color: "base-lighter",
// Form settings
$theme-form-font-family: "Source Sans Pro",
$theme-input-line-height-size: "lg",
);
Using Components
USWDS provides a comprehensive library of accessible, reusable components. Here are some of the most commonly used ones.
Buttons
Buttons communicate actions users can take. They are typically placed throughout your UI.
Button variants
<button class="usa-button" type="button">Primary button</button>
<button class="usa-button usa-button--secondary" type="button">Secondary</button>
<button class="usa-button usa-button--accent-cool" type="button">Accent cool</button>
<button class="usa-button usa-button--outline" type="button">Outline</button>
Forms
Form components collect information from users. USWDS provides accessible form patterns with proper labeling and validation.
Navigation
USWDS provides several navigation patterns for different contexts.
API Reference
Complete reference for all USWDS JavaScript components and their configuration options.
Accordion
| Property | Type | Default | Description |
|---|---|---|---|
multiSelect |
boolean | false | Allow multiple sections open at once |
openOnLoad |
boolean | false | Open specified sections on page load |
Modal
| Property | Type | Default | Description |
|---|---|---|---|
forceRole |
boolean | true | Force role="dialog" on modal element |
isModal |
boolean | true | Enable modal behavior (trap focus) |
Frequently Asked Questions
USWDS supports the latest versions of Chrome, Firefox, Safari, and Edge. It also provides graceful degradation for older browsers.
Yes. USWDS provides a vanilla JavaScript implementation, but you can use the CSS classes with any framework. Community-maintained React and Vue wrappers are also available.
Yes. USWDS components are designed to meet Section 508 accessibility requirements and WCAG 2.1 AA standards.
USWDS uses a design token system. You can override color tokens in your settings file or use the theme color variables in your custom SCSS.