Spacing
Notation
Spacing utility classes can be defined using the format -{property}{sides}[-{breakpoint}]--{size}
.
{property}
m
- use to applymargin
p
- use to applypadding
{sides}
t
- use to applymargin-top
orpadding-top
b
- use to applymargin-bottom
orpadding-bottom
l
- use to applymargin-left
orpadding-left
r
- use to applymargin-right
orpadding-right
x
- use to applymargin-left
andmargin-right
orpadding-left
andpadding-right
y
- use to applymargin-top
andmargin-bottom
orpadding-top
andpadding-bottom
- blank - leave blank to apply
margin
orpadding
to all 4 sides.
{breakpoint}
Optionally include -{breakpoint} to apply the utility behaviour to some breakpoints. As a mobile first library, any applying to smaller breakpoint will modify also larger ones unless other class overrides this behaviour.
- blank - leave blank to apply
margin
orpadding
to all breakpoints. sm
- use to applymargin
orpadding
to sm and larger breakpoints.md
- use to applymargin
orpadding
to md and larger breakpoints.lg
- use to applymargin
orpadding
to lg and larger breakpoints.xl
- use to applymargin
orpadding
to xl breakpoints.
{size}
0
- use to eliminate existingmargin
orpadding
and set to0
1
- use to setmargin
orpadding
to$base-unit
2
- use to setmargin
orpadding
to$base-unit * 2
3
- use to setmargin
orpadding
to$base-unit * 3
4
- use to setmargin
orpadding
to$base-unit * 4
5
- use to setmargin
orpadding
to$base-unit * 5
6
- use to setmargin
orpadding
to$base-unit * 6
7
- use to setmargin
orpadding
to$base-unit * 7
8
- use to setmargin
orpadding
to$base-unit * 8
9
- use to setmargin
orpadding
to$base-unit * 9
10
- use to setmargin
orpadding
to$base-unit * 10
auto
- use to setmargin
toauto
value
Examples
Margins
In this example, various margin classes have been applied to render margin on all 4 sides of the blue squares. The margin can be visualized in blue.
<div class="-m--2"></div>
<div class="-m--4"></div>
<div class="-m--6"></div>
Side Margins
Apply margin to specific sides of an element by adding t
,
b
, l
, r
, x
or y
to the class name.
<!-- margin-top -->
<div class="-mt--3"></div>
<!-- margin-bottom -->
<div class="-mb--3"></div>
<!-- margin-left -->
<div class="-ml--3"></div>
<!-- margin-right -->
<div class="-mr--3"></div>
<!-- margin-left and margin-right -->
<div class="-mx--3"></div>
<!-- margin-top and margin-bottom -->
<div class="-my--3"></div>
Padding
In this example, various padding classes have been applied to render padding on all 4 sides of the blue squares. The padding can be visualized in yellow.
<div class="-p--2"></div>
<div class="-p--4"></div>
<div class="-p--6"></div>
Side Paddings
Apply padding to specific sides of an element by adding t
,
b
, l
, r
, x
or y
to the class name.
<!-- padding-top -->
<div class="-pt--3"></div>
<!-- padding-bottom -->
<div class="-pb--3"></div>
<!-- padding-left -->
<div class="-pl--3"></div>
<!-- padding-right -->
<div class="-pr--3"></div>
<!-- padding-left and padding-right -->
<div class="-px--3"></div>
<!-- padding-top and padding-bottom -->
<div class="-py--3"></div>
Margin + Padding
Apply both margin and padding to an element by adding both class names.
<div class="-m--3 -p--3"></div>
Auto margin
Apply margin auto to an element
<div class="-m--auto"></div>
Breakpoints
Target specific breakpoints with responsive classes.
<div class="-mx--0 -px--0 -mx-lg--6 -px-lg--6"></div>