Utilities
Height and width
Set the dimensions of an item.
CSS properties
.maxh-none none
.maxh-05 4px
.maxh-1 8px
.maxh-105 12px
.maxh-2 16px
.maxh-205 20px
.maxh-3 24px
.maxh-4 32px
.maxh-5 40px
.maxh-6 48px
.maxh-7 56px
.maxh-8 64px
.maxh-9 72px
.maxh-10 80px
.maxh-15 120px
.maxh-card 160px
.maxh-card-lg 240px
.maxh-mobile 320px
.maxh-mobile-lg 480px
.maxh-tablet 640px
.maxh-tablet-lg 880px
.maxh-viewport 100vh
.maxw-none none
.maxw-05 4px
.maxw-1 8px
.maxw-105 12px
.maxw-2 16px
.maxw-205 20px
.maxw-3 24px
.maxw-4 32px
.maxw-5 40px
.maxw-6 48px
.maxw-7 56px
.maxw-8 64px
.maxw-9 72px
.maxw-10 80px
.maxw-15 120px
.maxw-card 160px
.maxw-card-lg 240px
.maxw-mobile 320px
.maxw-mobile-lg 480px
.maxw-tablet 640px
.maxw-tablet-lg 880px
.maxw-desktop 1024px
.maxw-desktop-lg 1200px
.maxw-widescreen 1400px
.maxw-full 100%
.minh-none none
.minh-0 0
.minh-05 4px
.minh-1 8px
.minh-105 12px
.minh-2 16px
.minh-205 20px
.minh-3 24px
.minh-4 32px
.minh-5 40px
.minh-6 48px
.minh-7 56px
.minh-8 64px
.minh-9 72px
.minh-10 80px
.minh-15 120px
.minh-card 160px
.minh-card-lg 240px
.minh-mobile 320px
.minh-mobile-lg 480px
.minh-tablet 640px
.minh-tablet-lg 880px
.minh-full 100%
.minh-viewport 100vh
.minw-none none
.minw-05 4px
.minw-1 8px
.minw-105 12px
.minw-2 16px
.minw-205 20px
.minw-3 24px
.minw-4 32px
.minw-5 40px
.minw-6 48px
.minw-7 56px
.minw-8 64px
.minw-9 72px
.minw-10 80px
.minw-15 120px
Utility mixins
Utilities may be used in component Sass with utility mixins. Highlighted tokens are the USWDS design tokens that serve as the foundation for all design system styles. Each token is also a documentation link. Consult the Design tokens section for more information on tokens and how to use them in USWDS.
Utility | Mixin | Example |
---|---|---|
.height-units | u-height(units) | @include u-height('card') |
.width-units | u-width(units) | @include u-width('auto') |
.maxh-units | u-maxh(units) | @include u-maxh('screen') |
.maxw-units | u-maxw(units) | @include u-maxw('card-lg') |
.minh-units | u-minh(units) | @include u-minh('screen') |
.minw-units | u-minw(units) | @include u-minw('auto') |
.add-aspect-ratio
|
add-aspect(ratio )
|
@include add-aspect('16x9') |
.circle-units | u-circle(units) | @include u-circle('05') |
.square-units | u-square(units) | @include u-square('05') |
Using utility mixins
- Use single-quoted strings in utility mixins. Do not quote numbers or px values, with the exception of half (
05
) values like'05'
,'105'
, and'205'
which should be treated as strings. - String tokens for half values (
05
) and negative values (likeneg-1
)may also be written with their unquoted number token equivalent:0.5
,1.5
,2.5
,2.5
,-1
,-1.5
, etc - If multiple utilities share the same prefix (ex:
.text-
or.flex-
) or a single utility accepts multiple kinds of values (ex:.border
accepts both border weight and border color), their shared mixin can accept multiple comma-separated values:u-text('primary-darkest', 'no-underline', 'bold')
oru-border-top(2px, 'accent-warm')
. - Output any utility mixin as
!important
by appending!important
to the mixin’s argument list:u-bg('red-warm-50v', !important)
.
Advanced settings
Responsive variants
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 name | Width | Default |
---|---|---|
card | 160px | false |
card-lg | 240px | false |
mobile | 320px | false |
mobile-lg | 480px | true |
tablet | 640px | true |
tablet-lg | 880px | false |
desktop | 1024px | true |
desktop-lg | 1200px | false |
widescreen | 1400px | false |
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 ) );
Utility variable | Default |
---|---|
$height-settings.responsive | false |
$width-settings.responsive | true |
$max-height-settings.responsive | false |
$max-width-settings.responsive | false |
$min-height-settings.responsive | false |
$min-width-settings.responsive | false |
$add-aspect-settings.responsive | false |
$circle-settings.responsive | false |
$square-settings.responsive | false |
State variants
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 ) );
Utility variable | active | focus | hover | visited |
---|---|---|---|---|
$height-settings | false | false | false | false |
$width-settings | false | false | false | false |
$max-height-settings | false | false | false | false |
$max-width-settings | false | false | false | false |
$min-height-settings | false | false | false | false |
$min-width-settings | false | false | false | false |
$add-aspect-settings | false | false | false | false |
$circle-settings | false | false | false | false |
$square-settings | false | false | false | false |
Output control
Control whether or not to output any USWDS utility family by setting the value of the $[utility_family]-settings.output
variable in your USWDS settings configuration.
A value of true
will output the utility family and any variants. A value of false
prevents the output of the family and any variants.
Utility variable | Default |
---|---|
$height-settings.output | true |
$width-settings.output | true |
$max-height-settings.output | true |
$max-width-settings.output | true |
$min-height-settings.output | true |
$min-width-settings.output | true |
$add-aspect-settings.output | true |
$circle-settings.output | true |
$square-settings.output | true |
Custom values
By default, USWDS utilities output the standard values listed in the standard output table. Customize and refine any utility family’s specific values by editing the $[utility_family]-manual-values
and $[utility_family]-palettes
variables in your USWDS settings configuration.
Manual values
Specify manual values as unique key:value
pairs using the $[utility_family]-manual-values
map, where the key
is the utility’s value suffix, and the value
is what the utility will output.
Example
$width-manual-values: ( 'tab': 4ch, );
Output
.width-tab { width: 4ch; }
Palettes
Palettes are predefined groups of values. Add palettes to the $[utility_family]-palettes
list variable in your USWDS settings configuration to add those values to the utility family.
Example
$width-palettes: ( 'palette-units-positive-large' // note: no trailing comma );
Output
.width-card { width: 10rem; } .width-card-lg { width: 15rem; } .width-mobile { width: 20rem; }
Default palettes
Palette name | Palette contents |
---|---|
'palette-height-default' | height default tokens |
'palette-width-default' | width default tokens |
'palette-max-height-default' | max-height default tokens |
'palette-max-width-default' | max-width default tokens |
'palette-min-height-default' | min-height default tokens |
'palette-min-width-default' | min-width default tokens |
'palette-add-aspect-default' | add-aspect default tokens |
'palette-circle-default' | circle default tokens |
'palette-square-default' | square default tokens |
Spacing and units
Palette name | Palette contents |
---|---|
'palette-units' | All spacing unit tokens (system, ch, em, percentage) |
'palette-units-system' | All system spacing unit tokens |
'palette-units-system-breakpoints' | All named spacing unit tokens: card, card-lg, mobile, mobile-lg, tablet, tablet-lg, desktop, desktop-lg, widescreen |
'palette-units-system-positive' | All positive spacing unit tokens |
'palette-units-system-positive-smaller' | 1px, 2px |
'palette-units-system-positive-small' | 05, 1, 105, 2, 205, 3 |
'palette-units-system-positive-medium' | 4, 5, 6, 7, 8, 9, 10, 15 |
'palette-units-system-positive-large' | card, card-lg, mobile |
'palette-units-system-positive-larger' | mobile-lg, tablet, tablet-lg |
'palette-units-system-positive-largest' | desktop, desktop-lg, widescreen |
'palette-units-system-negative' | All negative spacing values |
'palette-units-system-negative-smaller' | neg-1px, neg-2px |
'palette-units-system-negative-small' | neg-05, neg-1, neg-105, neg-2, neg-205, neg-3 |
'palette-units-ch' | 05ch, 1ch, 105ch, 2ch, 3ch, 4ch, 5ch, neg-05ch, neg-1ch, neg-105ch, neg-2ch, neg-3ch, neg-4ch, neg-5ch |
'palette-units-ch-positive' | 05ch, 1ch, 105ch, 2ch, 3ch, 4ch, 5ch |
'palette-units-ch-negative' | neg-05ch, neg-1ch, neg-105ch, neg-2ch, neg-3ch, neg-4ch, neg-5ch |
'palette-units-em' | 05em, 1em, 105em, 2em, 3em, 4em, 5em, 6em, 7em, 8em, 9em, 10em |
'palette-units-percentage' | 10ct, 20ct, 25ct, 30ct, 33ct, 40ct, 50ct, 60ct, 66ct, 75ct, 80ct, 90ct, 100ct |
'palette-units-0' | 0 |
Latest updates
Meaningful code and guidance updates are listed in the following table:
Date | USWDS version | Affects | Description |
---|---|---|---|
2022-08-05 | 3.1.0 |
|
Updated |
2021-10-20 | N/A |
|
Added the |