Link

Margin

Margin utilities are based on a global spacing scale which helps keep horizontal and vertical spacing consistent. These utilities help us reduce the amount of custom CSS that share the same properties, and allows to achieve many different page layouts using the same styles.

Naming convention

Since margin utilities have many variations and will be used in many places, we use a shorthand naming convention to help keep class names succinct.

Shorthand Description
m margin
t top
r right
b bottom
l left
x horizontal, left & right
y vertical, top & bottom
0 0
1 .25rem / 4px
2 .5rem / 8px
3 1rem / 16px
4 1.5rem / 24px
5 2rem / 32px
6 2.5rem / 40px

Uniform margins

Use uniform spacing utilities to apply equal margin to all sides of an element. These utilities can change or override default margins, and can be used with a spacing scale from 0-6.

.m-0-fluid
.m-1-fluid
.m-2-fluid
.m-3-fluid
.m-4-fluid
.m-5-fluid
.m-6-fluid

Directional margins

Use directional utilities to apply margin to an individual side, or the X and Y axis of an element. Directional utilities can change or override default margins, and can be used with a spacing scale of 0-6.

.mt-3-fluid
.mr-3-fluid
.mb-3-fluid
.ml-3-fluid
.mx-3-fluid
.my-3-fluid

Center elements

Use mx-auto to center block elements with a set width.

.mx-auto

Reset margins

Reset margins built into typography elements or other components with m-0-fluid, mt-0-fluid, mr-0-fluid, mb-0-fluid, ml-0-fluid, mx-0-fluid, and my-0-fluid.

No bottom margin on this paragraph.

Responsive margins

All margin utilities, except mx-auto, can be adjusted per breakpoint using the following formula: m[direction]-[breakpoint]-[spacer]. Each responsive style is applied to the specified breakpoint and up.

.mx-sm-2-fluid .mx-md-4-fluid

Negative margins

You can add negative margins to the top, right, bottom, or left of an item by adding a negative margin utility. The formula for this is: m[direction]-n[spacer]. This also works responsively, with the following formula: m[direction]-[breakpoint]-n[spacer].

.m-3-fluid .ml-n4-fluid .ml-md-n6-fluid