Skip to main content
An official website of the United States government

Utilities Overview

Utilities are simple HTML classes typically scoped to a single CSS property, like border-style or background-color. Utilities can be used additively to style an object from scratch or to override a style defined in component CSS. Utilities allow designers and developers to build and test new designs and components without abstracting their work into traditional semantic names or altering production CSS.

They also make it possible to create element-specific overrides without writing high-specificity variants into component CSS.

Utility Naming

Most USWDS utilities are built to assign a single CSS property a single value. Our utilities are named .[base]-[value], where [base] is often the name of the CSS property the utility targets and the parts of the utility name are separated by a hyphen. For example, margin-top-2. Our utility classes are designed to make sense at a glance to anyone familiar with standard CSS properties.

For a complete list of the utilities and their bases, see each utility’s documentation page, or the Modules table, below.

The utility values are drawn from your project theme-settings tokens but can be extended to include additional values drawn from our palette of common units (like px, em, ch, and percentages) as well as the broader USWDS system palette of colors, grid spacing, and font scale. (Each utility’s Advanced settings section provides more information on customization.)

USWDS UtilitySass
.bg-primary-darkerbackground-color: color('primary-darker')
.bg-red-50vbackground-color: color('red-50v')
.text-underlinetext-decoration: underline
.margin-x-automargin-left-auto
margin-right-auto
.padding-bottom-1padding-bottom: units(1)

Utility Class Modifiers

Utility modules can be configured to output additional CSS classes for targeting specific breakpoints or the link-related pseudo-classes. Each utility module under Foundations documents which modifiers are enabled by default.

Responsive Modifiers

Add a responsive breakpoint prefix separated with a : to target a utility at a responsive breakpoint and higher, following a mobile-first methodology.

Example

.tablet:padding-y-2

Output

@media screen and (min-width: 640px) {
.tablet\:padding-y-2 {
padding-top: 1rem;
padding-bottom: 1rem;
}
}

Set up which breakpoints are available to USWDS utilities by setting the $theme-utility-breakpoints variable in your USWDS settings configuration.

Breakpoint NameWidthDefault
card160pxfalse
card-lg240pxfalse
mobile320pxtrue
mobile-lg480pxtrue
tablet640pxtrue
tablet-lg880pxfalse
desktop1024pxtrue
desktop-lg1200pxfalse
widescreen1400pxtrue

Set whether a utility family outputs with responsive variants by setting the value of $[utility_family]-settings.responsive in your USWDS settings configuration. When modifying settings stored as a map, undefined map elements will keep their default values.

Example

@use "uswds-core" with (
$background-color-settings: (
responsive: true
)
);

State Modifiers

Use a state prefix separated with a : to target a utility in a specific state.

Example

.hover:bg-primary-vivid

Output

.hover\:bg-primary-vivid:hover { background-color: #0052de; }

Set whether a utility outputs a specific state variant by setting the value of the $[utility_family]-settings.[state] variable in your USWDS settings configuration. When modifying settings stored as a map, undefined map elements will keep their default values.

Example

@use "uswds-core" with (
$background-color-settings: (
active: true
)
);

Utilities Package, Settings, and Modules

USWDS provides a useful default set of utilities that developers can extend and modify in their project’s settings to suit their project’s needs and their development preferences.

Utilities are included by default as part of the uswds bundle package that most projects use. (Read more about packages here.)

If you unbundle your project’s packages, include utilities with the uswds-utilities package. This package includes all of the USWDS utilities available to the design system. Each utility is configured differently — some have responsive and state variants enabled. Each utility’s default output is documented on its documentation page.

The entire package is 198 KB uncompressed.

Include the uswds-utilities package in your project’s Sass entry point with a module forward:

@forward "uswds-utilities";

Settings

You can further customize utility output with USWDS settings. Add settings from the table below to your uswds-core module initialization. For more information on configuring USWDS settings, visit the settings page. Here’s an example:

Utility Modules

Utility Module Name
Gzip File Size
Non-Gzip File Size
add-aspect
0.08
0.44
add-list-reset
0.02
0.12
align-items
0.04
0.24
align-self
0.06
0.31
background-color
1
5.4
border
4.35
23.5
border-color
4.35
23.5
border-radius
1.61
8.7
border-style
0.03
0.14
border-width
0.56
3
bottom
0.18
0.96
box-shadow
0.06
0.33
circle
0.19
1
clearfix
0.02
0.09
color
0.37
2
cursor
0.07
0.39
display
0.28
1.5
flex
0.06
0.33
flex-direction
0.02
0.1
flex-wrap
0.02
0.1
float
0.02
0.1
font
2.41
13
font-family
0.37
2
font-feature
0.03
0.14
font-style
0.02
0.11
font-weight
0.1
0.54
height
0.11
0.6
justify-content
0.18
0.95
left
0.08
0.44
letter-spacing
0.05
0.28
line-height
1.61
8.7
margin
0.8
4.35
margin-horizontal
4.02
21.75
margin-vertical
4.02
21.75
max-height
0.12
0.65
max-width
0.13
0.72
measure
0.18
0.98
min-height
0.13
0.72
min-width
0.07
0.4
opacity
0.24
1.3
order
0.26
1.4
outline
0.03
0.18
outline-color
0.56
3
overflow
0.09
0.46
padding
4.02
21.75
pin
0.06
0.35
position
0.04
0.21
right
0.09
0.47
square
0.14
0.73
text-align
0.03
0.16
text-decoration
0.06
0.32
text-decoration-color
2.33
12.6
text-indent
0.19
1
text-transform
0.04
0.2
top
0.07
0.4
vertical-align
0.06
0.32
whitespace
0.04
0.2
width
0.56
3
z-index
0.04
0.22