Utilities

Margin and padding

Change the spacing around an item and inside an item.

CSS properties

margin padding

Examples and usage

Utilities, values, and variants may be activated and deactivated in advanced settings.

Margin

CSS property: margin

Margin on all sides

.margin-0
0
.margin-1px
1px
.margin-2px
2px
.margin-05
4px
.margin-1
8px
.margin-105
12px
.margin-2
16px
.margin-205
20px
.margin-3
24px
.margin-4
32px
.margin-5
40px
.margin-6
48px
.margin-7
56px
.margin-8
64px
.margin-9
72px
.margin-10
80px
.margin-15
120px

Margin bottom

.margin-bottom-neg-15
-120px
.margin-bottom-neg-10
-80px
.margin-bottom-neg-9
-72px
.margin-bottom-neg-8
-64px
.margin-bottom-neg-7
-56px
.margin-bottom-neg-6
-48px
.margin-bottom-neg-5
-40px
.margin-bottom-neg-4
-32px
.margin-bottom-neg-3
-24px
.margin-bottom-neg-205
-20px
.margin-bottom-neg-2
-16px
.margin-bottom-neg-105
-12px
.margin-bottom-neg-1
-8px
.margin-bottom-neg-05
-4px
.margin-bottom-neg-2px
-2px
.margin-bottom-neg-1px
-1px
.margin-bottom-0
0
.margin-bottom-1px
1px
.margin-bottom-2px
2px
.margin-bottom-05
4px
.margin-bottom-1
8px
.margin-bottom-105
12px
.margin-bottom-2
16px
.margin-bottom-205
20px
.margin-bottom-3
24px
.margin-bottom-4
32px
.margin-bottom-5
40px
.margin-bottom-6
48px
.margin-bottom-7
56px
.margin-bottom-8
64px
.margin-bottom-9
72px
.margin-bottom-10
80px
.margin-bottom-15
120px

Margin top

.margin-top-neg-15
-120px
.margin-top-neg-10
-80px
.margin-top-neg-9
-72px
.margin-top-neg-8
-64px
.margin-top-neg-7
-56px
.margin-top-neg-6
-48px
.margin-top-neg-5
-40px
.margin-top-neg-4
-32px
.margin-top-neg-3
-24px
.margin-top-neg-205
-20px
.margin-top-neg-2
-16px
.margin-top-neg-105
-12px
.margin-top-neg-1
-8px
.margin-top-neg-05
-4px
.margin-top-neg-2px
-2px
.margin-top-neg-1px
-1px
.margin-top-0
0
.margin-top-1px
1px
.margin-top-2px
2px
.margin-top-05
4px
.margin-top-1
8px
.margin-top-105
12px
.margin-top-2
16px
.margin-top-205
20px
.margin-top-3
24px
.margin-top-4
32px
.margin-top-5
40px
.margin-top-6
48px
.margin-top-7
56px
.margin-top-8
64px
.margin-top-9
72px
.margin-top-10
80px
.margin-top-15
120px

Margin left

.margin-left-neg-15
-120px
.margin-left-neg-10
-80px
.margin-left-neg-9
-72px
.margin-left-neg-8
-64px
.margin-left-neg-7
-56px
.margin-left-neg-6
-48px
.margin-left-neg-5
-40px
.margin-left-neg-4
-32px
.margin-left-neg-3
-24px
.margin-left-neg-205
-20px
.margin-left-neg-2
-16px
.margin-left-neg-105
-12px
.margin-left-neg-1
-8px
.margin-left-neg-05
-4px
.margin-left-neg-2px
-2px
.margin-left-neg-1px
-1px
.margin-left-0
0
.margin-left-1px
1px
.margin-left-2px
2px
.margin-left-05
4px
.margin-left-1
8px
.margin-left-105
12px
.margin-left-2
16px
.margin-left-205
20px
.margin-left-3
24px
.margin-left-4
32px
.margin-left-5
40px
.margin-left-6
48px
.margin-left-7
56px
.margin-left-8
64px
.margin-left-9
72px
.margin-left-10
80px
.margin-left-15
120px
.margin-left-auto
auto

Margin right

.margin-right-neg-15
-120px
.margin-right-neg-10
-80px
.margin-right-neg-9
-72px
.margin-right-neg-8
-64px
.margin-right-neg-7
-56px
.margin-right-neg-6
-48px
.margin-right-neg-5
-40px
.margin-right-neg-4
-32px
.margin-right-neg-3
-24px
.margin-right-neg-205
-20px
.margin-right-neg-2
-16px
.margin-right-neg-105
-12px
.margin-right-neg-1
-8px
.margin-right-neg-05
-4px
.margin-right-neg-2px
-2px
.margin-right-neg-1px
-1px
.margin-right-0
0
.margin-right-1px
1px
.margin-right-2px
2px
.margin-right-05
4px
.margin-right-1
8px
.margin-right-105
12px
.margin-right-2
16px
.margin-right-205
20px
.margin-right-3
24px
.margin-right-4
32px
.margin-right-5
40px
.margin-right-6
48px
.margin-right-7
56px
.margin-right-8
64px
.margin-right-9
72px
.margin-right-10
80px
.margin-right-15
120px
.margin-right-auto
auto

Margin left and right

.margin-x-neg-15
-120px
.margin-x-neg-10
-80px
.margin-x-neg-9
-72px
.margin-x-neg-8
-64px
.margin-x-neg-7
-56px
.margin-x-neg-6
-48px
.margin-x-neg-5
-40px
.margin-x-neg-4
-32px
.margin-x-neg-3
-24px
.margin-x-neg-205
-20px
.margin-x-neg-2
-16px
.margin-x-neg-105
-12px
.margin-x-neg-1
-8px
.margin-x-neg-05
-4px
.margin-x-neg-2px
-2px
.margin-x-neg-1px
-1px
.margin-x-0
0
.margin-x-1px
1px
.margin-x-2px
2px
.margin-x-05
4px
.margin-x-1
8px
.margin-x-105
12px
.margin-x-2
16px
.margin-x-205
20px
.margin-x-3
24px
.margin-x-4
32px
.margin-x-5
40px
.margin-x-6
48px
.margin-x-7
56px
.margin-x-8
64px
.margin-x-9
72px
.margin-x-10
80px
.margin-x-15
120px
.margin-x-auto
auto

Margin bottom and top

.margin-y-neg-15
-120px
.margin-y-neg-10
-80px
.margin-y-neg-9
-72px
.margin-y-neg-8
-64px
.margin-y-neg-7
-56px
.margin-y-neg-6
-48px
.margin-y-neg-5
-40px
.margin-y-neg-4
-32px
.margin-y-neg-3
-24px
.margin-y-neg-205
-20px
.margin-y-neg-2
-16px
.margin-y-neg-105
-12px
.margin-y-neg-1
-8px
.margin-y-neg-05
-4px
.margin-y-neg-2px
-2px
.margin-y-neg-1px
-1px
.margin-y-0
0
.margin-y-1px
1px
.margin-y-2px
2px
.margin-y-05
4px
.margin-y-1
8px
.margin-y-105
12px
.margin-y-2
16px
.margin-y-205
20px
.margin-y-3
24px
.margin-y-4
32px
.margin-y-5
40px
.margin-y-6
48px
.margin-y-7
56px
.margin-y-8
64px
.margin-y-9
72px
.margin-y-10
80px
.margin-y-15
120px

Padding

CSS property: padding

Padding on all sides

.padding-0
0
.padding-1px
1px
.padding-2px
2px
.padding-05
4px
.padding-1
8px
.padding-105
12px
.padding-2
16px
.padding-205
20px
.padding-3
24px
.padding-4
32px
.padding-5
40px
.padding-6
48px
.padding-7
56px
.padding-8
64px
.padding-9
72px
.padding-10
80px
.padding-15
120px

Padding bottom

.padding-bottom-0
0
.padding-bottom-1px
1px
.padding-bottom-2px
2px
.padding-bottom-05
4px
.padding-bottom-1
8px
.padding-bottom-105
12px
.padding-bottom-2
16px
.padding-bottom-205
20px
.padding-bottom-3
24px
.padding-bottom-4
32px
.padding-bottom-5
40px
.padding-bottom-6
48px
.padding-bottom-7
56px
.padding-bottom-8
64px
.padding-bottom-9
72px
.padding-bottom-10
80px
.padding-bottom-15
120px

Padding top

.padding-top-0
0
.padding-top-1px
1px
.padding-top-2px
2px
.padding-top-05
4px
.padding-top-1
8px
.padding-top-105
12px
.padding-top-2
16px
.padding-top-205
20px
.padding-top-3
24px
.padding-top-4
32px
.padding-top-5
40px
.padding-top-6
48px
.padding-top-7
56px
.padding-top-8
64px
.padding-top-9
72px
.padding-top-10
80px
.padding-top-15
120px

Padding left

.padding-left-0
0
.padding-left-1px
1px
.padding-left-2px
2px
.padding-left-05
4px
.padding-left-1
8px
.padding-left-105
12px
.padding-left-2
16px
.padding-left-205
20px
.padding-left-3
24px
.padding-left-4
32px
.padding-left-5
40px
.padding-left-6
48px
.padding-left-7
56px
.padding-left-8
64px
.padding-left-9
72px
.padding-left-10
80px
.padding-left-15
120px

Padding right

.padding-right-0
0
.padding-right-1px
1px
.padding-right-2px
2px
.padding-right-05
4px
.padding-right-1
8px
.padding-right-105
12px
.padding-right-2
16px
.padding-right-205
20px
.padding-right-3
24px
.padding-right-4
32px
.padding-right-5
40px
.padding-right-6
48px
.padding-right-7
56px
.padding-right-8
64px
.padding-right-9
72px
.padding-right-10
80px
.padding-right-15
120px

Padding left and right

.padding-x-0
0
.padding-x-1px
1px
.padding-x-2px
2px
.padding-x-05
4px
.padding-x-1
8px
.padding-x-105
12px
.padding-x-2
16px
.padding-x-205
20px
.padding-x-3
24px
.padding-x-4
32px
.padding-x-5
40px
.padding-x-6
48px
.padding-x-7
56px
.padding-x-8
64px
.padding-x-9
72px
.padding-x-10
80px
.padding-x-15
120px

Padding bottom and top

.padding-y-0
0
.padding-y-1px
1px
.padding-y-2px
2px
.padding-y-05
4px
.padding-y-1
8px
.padding-y-105
12px
.padding-y-2
16px
.padding-y-205
20px
.padding-y-3
24px
.padding-y-4
32px
.padding-y-5
40px
.padding-y-6
48px
.padding-y-7
56px
.padding-y-8
64px
.padding-y-9
72px
.padding-y-10
80px
.padding-y-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
.margin-modifier-units u-margin-modifier(units) @include u-margin-x(-0.5)
.padding-modifier-units u-padding-modifier(units) @include u-padding(1)

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 (like neg-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') or u-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
$margin-settings.responsive true
$padding-settings.responsive true

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
$margin-settings false false false false
$padding-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
$margin-settings.output true
$padding-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

$margin-palettes: (
  'palette-units-positive-smaller',
  'palette-units-negative-smaller', // note: no trailing comma
);

Output

.margin-1px { margin: 1px; }
.margin-2px { margin: 2px; }
.margin-neg-1px { margin: -1px; }
.margin-neg-2px { margin: -2px; }

Default palettes

Palette name Palette contents
'palette-margin-default' margin default tokens
'palette-padding-default' padding 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 Breaking Description
2021-12-21 N/A
  • Guidance
No

Added documentation for values 10, 15, and margin-neg-4 through margin-neg-15. More information: uswds-site#1940

2021-12-21 N/A
  • Guidance
No

Fixed the example display for “Padding on all sides”. More information: uswds-site#1940

2021-06-16 2.12.0
  • Styles
No

Added margin-neg-4 through margin-neg-15 to the default set. More information: uswds#4212