CSS Spacing
These utility classes modify an element's appearance by adjusting its margins and padding.
Margin and padding
Use the spacing utilities to give margin
or padding
values to an element or a subset of its sides. The spacing utilities have support for individual properties, all properties, and vertical and horizontal properties. Classes are made from a default Sass map that ranges from .5rem
to 6rem
, where 1rem
is equivalent to 16px
.
Example
To have spacing utilities inherit on all breakpoints, don't add a breakpoint abbreviation to them. If you wish to have spacing utilities on specific breakpoints, use sm
, md
, lg
, and xl
. Remember, every breakpoint above the one you specify will inherit the spacing, so be sure to keep that in mind (e.g., if added on sm
, will also add spacing on md
, lg
, and xl
).
The classes are named using the format {property}{sides}-{size}
for xs
and {property}{sides}-{breakpoint}-{size}
for sm
, md
, lg
, and xl
.
Where property is one of:
m
— for classes that setmargin
p
— for classes that setpadding
Where sides is one of:
t
— for classes that setmargin-top
orpadding-top
b
— for classes that setmargin-bottom
orpadding-bottom
l
— for classes that setmargin-left
orpadding-left
r
— for classes that setmargin-right
orpadding-right
x
— for classes that set both*-left
and*-right
y
— for classes that set both*-top
and*-bottom
- blank — for classes that set a
margin
orpadding
on all four sides of the element
Where size is one of:
0
— for classes that eliminate the span,margin
, orpadding
by setting it to0
0_25
— (by default) for classes that set themargin
orpadding
to0.25rem
or4px
0_5
— (by default) for classes that set themargin
orpadding
to0.5rem
or8px
0_75
— (by default) for classes that set themargin
orpadding
to0.75rem
or12px
1
— (by default) for classes that set themargin
orpadding
to1rem
or16px
1_5
— (by default) for classes that set themargin
orpadding
to1.5rem
or24px
2
— (by default) for classes that set themargin
orpadding
to2rem
or32px
2_5
— (by default) for classes that set themargin
orpadding
to2.5rem
or40px
3
— (by default) for classes that set themargin
orpadding
to3rem
or48px
3_5
— (by default) for classes that set themargin
orpadding
to3.5rem
or56px
4
— (by default) for classes that set themargin
orpadding
to4rem
or64px
4_5
— (by default) for classes that set themargin
orpadding
to4.5rem
or72px
5
— (by default) for classes that set themargin
orpadding
to5rem
or80px
5_5
— (by default) for classes that set themargin
orpadding
to5.5rem
or88px
6
— (by default) for classes that set themargin
orpadding
to6rem
or96px
auto
- for classes that set themargin
toauto
Gap
Gap utility classes let you control spacing between flex or grid children by applying them directly to the parent container — no need to add individual margins to each item. These utilities are responsive by default and follow our spacing scale, making it easy to maintain consistent layouts across breakpoints.
Usage
Use these classes to set consistent gaps across rows and columns, or just one direction. Replace *
with a spacing size (e.g., 0, 1, 2, 3, 4, 5, etc.), and {breakpoint}
with a responsive prefix (sm, md, lg, xl).
g-*
— Sets both row and column gap to*
g-{breakpoint}-{size}
— Sets both row and column gap at a specific breakpointgx-*
— Sets horizontal (column) gap to*
gx-{breakpoint}-{size}
— Sets horizontal gap at a specific breakpointgy-*
— Sets vertical (row) gap to*
gy-{breakpoint}-{size}
— Sets vertical gap at a specific breakpoint
Example
Do you have an idea, or want to help us improve this page? Reach out to us via email.
DTMB-DG-Support@michigan.govNeed help? Visit our Support page to learn how to get assistance, troubleshoot issues, and connect with the team.