Margin and padding
Utility spacing scale
Spacer suffix | REM | PX | Token |
---|---|---|---|
-0 | 0 | 0 | 0 |
-1 | 0.125rem | 2px | —units-25 |
-2 | 0.25rem | 4px | —units-50 |
-3 | 0.375rem | 6px | —units-75 |
-4 | 0.5rem | 8px | —units-100 |
-5 | 0.75rem | 12px | —units-150 |
-6 | 1rem | 16px | —units-200 |
-7 | 1.25rem | 20px | —units-250 |
-8 | 1.5rem | 24px | —units-300 |
-9 | 2rem | 32px | —units-400 |
-10 | 2.5rem | 40px | —units-500 |
:::info Spacing scale Our spacing system is built around a base unit of 8 pixels :::
Margin
Spacing utility classes can be used to effect four directions — top (block-start), right (inline-end), bottom (block-end), left (inline-start). In addition, you can effect just left/right (inline) top/bottom (block). Finally, you can effect all directions at once by no specifying a direction or an axis.
Margin prefixes
Margin prefix | Dimension | Copy |
---|---|---|
m- | all dimensions (x and y) | |
mt- | top | |
mr- | right | |
mb- | bottom | |
ml- | left | |
mx- | x-dimension (left and right/inline) | |
my- | y-dimension (top and bottom/block) |
Padding
Padding is exactly the same as margin, simply swapping the “m” in the prefix with a “p”.
Padding prefix | Dimension | Copy |
---|---|---|
p- | all dimensions (x and y) | |
pt- | top | |
pr- | right | |
pb- | bottom | |
pl- | left | |
px- | x-dimension (left and right/inline) | |
py- | y-dimension (top and bottom/block) |
Breakpoint infixes
Add the viewport sizing infixes (sm
, md
, lg
, xl
, xxl
) to apply at breakpoints. These infixes apply to both padding and margin.
.{prefix}-{infix}-{suffix}
XS | Small | Medium | Large | XL | XXL | Copy | |
---|---|---|---|---|---|---|---|
.mt-6 | has top margin | has top margin | has top margin | has top margin | has top margin | has top margin | |
.mt-sm-6 | no top margin | has top margin | has top margin | has top margin | has top margin | has top margin | |
.mt-md-6 | no top margin | no top margin | has top margin | has top margin | has top margin | has top margin | |
.mt-lg-6 | no top margin | no top margin | no top margin | has top margin | has top margin | has top margin | |
.mt-xl-6 | no top margin | no top margin | no top margin | no top margin | has top margin | has top margin | |
.mt-xxl-6 | no top margin | no top margin | no top margin | no top margin | no top margin | has top margin |
Responsiveness
Below is an illustration of the responsive cascade. The pattern follows the “mobile first” model.
XS | Small | Medium | Large | XL | XXL | Copy | |
---|---|---|---|---|---|---|---|
m-2 | —units-50 | —units-50 | —units-50 | —units-50 | —units-50 | —units-50 | |
m-2 m-sm-4 | —units-50 | —units-100 | —units-100 | —units-100 | —units-100 | —units-100 | |
m-2 m-sm-4 m-md-6 | —units-50 | —units-100 | —units-200 | —units-200 | —units-200 | —units-200 | |
m-2 m-sm-4 m-md-6 m-lg-8 | —units-50 | —units-100 | —units-200 | —units-300 | —units-300 | —units-300 | |
m-2 m-sm-4 m-md-6 m-lg-8 m-xl-9 | —units-50 | —units-100 | —units-200 | —units-300 | —units-400 | —units-400 | |
m-2 m-sm-4 m-md-6 m-lg-8 m-xxl-10 | —units-50 | —units-100 | —units-200 | —units-300 | —units-400 | —units-500 |
Examples .p-6
= “Padding everywhere inside this element (using the 6
spacer size)” .mx-3
= “Spacer size 3 to the left and right of this element”
.pl-5
= “Spacer size 5 on this element’s left side” .mb-2
= “Spacer size 1
below this element” .pl-lg-5
= “Padding equal to spacer size
--units-150
for large screens (and up) on the left side of the element.”