Utilities

Flex

Set an item’s flexbox properties.

CSS properties

align-items align-self flex flex-direction flex-wrap justify-content order

Examples and usage

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

Flex

CSS property: flex

  • responsive
  • active
  • hover
  • focus
  • visited
.flex-1
.flex-1
.flex-1
.flex-1
.flex-2
.flex-3
.flex-4
.flex-5
.flex-6
.flex-7
.flex-8
.flex-9
.flex-10
.flex-11
.flex-12
.flex-auto
.flex-fill
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<div class="grid-row">
  <div class="grid-col flex-1"></div>
  <div class="grid-col flex-1"></div>
  <div class="grid-col flex-1"></div>
  <div class="grid-col flex-1"></div>
</div>
<div class="grid-row">
  <div class="grid-col flex-2"></div>
  <div class="grid-col flex-1"></div>
  <div class="grid-col flex-1"></div>
  <div class="grid-col flex-1"></div>
</div>
<div class="grid-row">
  <div class="grid-col flex-3"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-4"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-5"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-6"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-7"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-8"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-9"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-10"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-11"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-12"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-auto"></div>
  ...
</div>
<div class="grid-row">
  <div class="grid-col flex-fill"></div>
  ...
</div>

Flex direction

CSS property: flex-direction

  • responsive
  • active
  • hover
  • focus
  • visited
.flex-column
.flex-row
1
2
3
4
5
6
7
8
9
10
11
12
<div class="grid-row flex-column">
  <div class="grid-col"></div>
  <div class="grid-col"></div>
  <div class="grid-col"></div>
  <div class="grid-col"></div>
</div>
<div class="grid-row flex-row">
  <div class="grid-col"></div>
  <div class="grid-col"></div>
  <div class="grid-col"></div>
  <div class="grid-col"></div>
</div>

Flex wrap

CSS property: flex-wrap

  • responsive
  • active
  • hover
  • focus
  • visited
.flex-wrap
.grid-col-4
.grid-col-4
.grid-col-4
.grid-col-4
.flex-no-wrap
.grid-col-4
.grid-col-4
.grid-col-4
.grid-col-4
1
2
3
4
5
6
7
8
9
10
11
12
<div class="grid-row flex-wrap">
  <div class="grid-col-4"></div>
  <div class="grid-col-4"></div>
  <div class="grid-col-4"></div>
  <div class="grid-col-4"></div>
</div>
<div class="grid-row flex-no-wrap">
  <div class="grid-col-4"></div>
  <div class="grid-col-4"></div>
  <div class="grid-col-4"></div>
  <div class="grid-col-4"></div>
</div>

Flex align

CSS property: align-items

  • responsive
  • active
  • hover
  • focus
  • visited
.flex-column
.flex-align-start
.flex-align-center
.flex-align-end
.flex-align-stretch
.flex-row
.flex-align-start
.flex-align-center
.flex-align-end
.flex-align-stretch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<div class="display-flex flex-column flex-align-start">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-column flex-align-center">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-column flex-align-end">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-column flex-align-stretch">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-row flex-align-start">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-row flex-align-center">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-row flex-align-end">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-row flex-align-stretch">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

Flex align self

CSS property: align-self

  • responsive
  • active
  • hover
  • focus
  • visited
.flex-column
.flex-align-self-start
.flex-align-self-center
.flex-align-self-end
.flex-align-self-stretch
.flex-row
.flex-align-self-start
.flex-align-self-center
.flex-align-self-end
.flex-align-self-stretch
1
2
3
4
5
6
7
8
9
10
11
12
13
<div class="display-flex flex-column">
  <div class="flex-align-self-start"></div>
  <div class="flex-align-self-center"></div>
  <div class="flex-align-self-end"></div>
  <div class="flex-align-self-stretch"></div>
</div>

<div class="display-flex flex-row">
  <div class="flex-align-self-start"></div>
  <div class="flex-align-self-center"></div>
  <div class="flex-align-self-end"></div>
  <div class="flex-align-self-stretch"></div>
</div>

Flex justify

CSS property: justify-content

  • responsive
  • active
  • hover
  • focus
  • visited
.flex-row
.flex-justify
.flex-justify-start
.flex-justify-center
.flex-justify-end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<div class="display-flex flex-column flex-justify">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-column flex-justify-start">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-column flex-justify-center">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-column flex-justify-end">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-row flex-justify">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-row flex-justify-start">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-row flex-justify-center">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

<div class="display-flex flex-row flex-justify-end">
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
  <div class="example"></div>
</div>

Order

CSS property: order

intital: 1 .order-11
intital: 2 .order-10
intital: 3 .order-9
intital: 4 .order-8
intital: 5 .order-7
intital: 6 .order-6
intital: 7 .order-5
intital: 8 .order-4
intital: 9 .order-3
intital: 10 .order-2
intital: 11 .order-1
intital: 12 .order-0
intital: 13 .order-initial
intital: 14 .order-last
intital: 15 .order-first
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<div class="grid-row">
  <div class="grid-col order-11"></div>
  <div class="grid-col order-10"></div>
  <div class="grid-col order-9"></div>
  <div class="grid-col order-8"></div>
  <div class="grid-col order-7"></div>
  <div class="grid-col order-6"></div>
  <div class="grid-col order-5"></div>
  <div class="grid-col order-4"></div>
  <div class="grid-col order-3"></div>
  <div class="grid-col order-2"></div>
  <div class="grid-col order-1"></div>
  <div class="grid-col order-0"></div>
  <div class="grid-col order-initial"></div>
  <div class="grid-col order-last"></div>
  <div class="grid-col order-first"></div>
</div>

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
.flex-flex u-flex(flex) @include u-flex('fill')
.flex-direction u-flex(direction) @include u-flex('row')
.flex-wrap u-flex(wrap) @include u-flex('no-wrap')
.flex-align-value u-flex('align-value') @include u-flex('align-center')
.flex-align-self-value u-flex('align-self-value') @include u-flex('align-self-center')
.flex-justify-value u-flex('justify-value') @include u-flex('justify')
.order-order u-order(order) @include u-order('last')

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
$flex-settings.responsive false
$flex-direction-settings.responsive false
$flex-wrap-settings.responsive false
$align-items-settings.responsive false
$align-self-settings.responsive false
$justify-content-settings.responsive false
$order-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
$flex-settings false false false false
$flex-direction-settings false false false false
$flex-wrap-settings false false false false
$align-items-settings false false false false
$align-self-settings false false false false
$justify-content-settings false false false false
$order-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
$flex-settings.output true
$flex-direction-settings.output true
$flex-wrap-settings.output true
$align-items-settings.output true
$align-self-settings.output true
$justify-content-settings.output true
$order-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.

There are no custom palettes associated with these utilities.