Quick reference
| Class | Properties |
|---|---|
.m-0 | margin: 0; |
.m-1 | margin: 0.25rem; /* 4px */ |
.m-2 | margin: 0.5rem; /* 8px */ |
.m-3 | margin: 0.75rem; /* 12px */ |
.m-4 | margin: 1rem; /* 16px */ |
.m-5 | margin: 1.25rem; /* 20px */ |
.m-6 | margin: 1.5rem; /* 24px */ |
.m-7 | margin: 1.75rem; /* 28px */ |
.m-8 | margin: 2rem; /* 32px */ |
.m-9 | margin: 2.25rem; /* 36px */ |
.m-10 | margin: 2.5rem; /* 40px */ |
.m-11 | margin: 2.75rem; /* 44px */ |
.m-12 | margin: 3rem; /* 48px */ |
.m-14 | margin: 3.5rem; /* 56px */ |
.m-16 | margin: 4rem; /* 64px */ |
.m-20 | margin: 5rem; /* 80px */ |
.m-auto | margin: auto; |
.mx-0 | margin-left: 0; margin-right: 0; |
.mx-1 | margin-left: 0.25rem; /* 4px */ margin-right: 0.25rem; /* 4px */ |
.mx-2 | margin-left: 0.5rem; /* 8px */ margin-right: 0.5rem; /* 8px */ |
.mx-3 | margin-left: 0.75rem; /* 12px */ margin-right: 0.75rem; /* 12px */ |
.mx-4 | margin-left: 1rem; /* 16px */ margin-right: 1rem; /* 16px */ |
.mx-5 | margin-left: 1.25rem; /* 20px */ margin-right: 1.25rem; /* 20px */ |
.mx-6 | margin-left: 1.5rem; /* 24px */ margin-right: 1.5rem; /* 24px */ |
.mx-7 | margin-left: 1.75rem; /* 28px */ margin-right: 1.75rem; /* 28px */ |
.mx-8 | margin-left: 2rem; /* 32px */ margin-right: 2rem; /* 32px */ |
.mx-9 | margin-left: 2.25rem; /* 36px */ margin-right: 2.25rem; /* 36px */ |
.mx-10 | margin-left: 2.5rem; /* 40px */ margin-right: 2.5rem; /* 40px */ |
.mx-11 | margin-left: 2.75rem; /* 44px */ margin-right: 2.75rem; /* 44px */ |
.mx-12 | margin-left: 3rem; /* 48px */ margin-right: 3rem; /* 48px */ |
.mx-14 | margin-left: 3.5rem; /* 56px */ margin-right: 3.5rem; /* 56px */ |
.mx-16 | margin-left: 4rem; /* 64px */ margin-right: 4rem; /* 64px */ |
.mx-20 | margin-left: 5rem; /* 80px */ margin-right: 5rem; /* 80px */ |
.mx-auto | margin-left: auto; margin-right: auto; |
.my-0 | margin-top: 0; margin-bottom: 0; |
.my-1 | margin-top: 0.25rem; /* 4px */ margin-bottom: 0.25rem; /* 4px */ |
.my-2 | margin-top: 0.5rem; /* 8px */ margin-bottom: 0.5rem; /* 8px */ |
.my-3 | margin-top: 0.75rem; /* 12px */ margin-bottom: 0.75rem; /* 12px */ |
.my-4 | margin-top: 1rem; /* 16px */ margin-bottom: 1rem; /* 16px */ |
.my-5 | margin-top: 1.25rem; /* 20px */ margin-bottom: 1.25rem; /* 20px */ |
.my-6 | margin-top: 1.5rem; /* 24px */ margin-bottom: 1.5rem; /* 24px */ |
.my-7 | margin-top: 1.75rem; /* 28px */ margin-bottom: 1.75rem; /* 28px */ |
.my-8 | margin-top: 2rem; /* 32px */ margin-bottom: 2rem; /* 32px */ |
.my-9 | margin-top: 2.25rem; /* 36px */ margin-bottom: 2.25rem; /* 36px */ |
.my-10 | margin-top: 2.5rem; /* 40px */ margin-bottom: 2.5rem; /* 40px */ |
.my-11 | margin-top: 2.75rem; /* 44px */ margin-bottom: 2.75rem; /* 44px */ |
.my-12 | margin-top: 3rem; /* 48px */ margin-bottom: 3rem; /* 48px */ |
.my-14 | margin-top: 3.5rem; /* 56px */ margin-bottom: 3.5rem; /* 56px */ |
.my-16 | margin-top: 4rem; /* 64px */ margin-bottom: 4rem; /* 64px */ |
.my-20 | margin-top: 5rem; /* 80px */ margin-bottom: 5rem; /* 80px */ |
.my-auto | margin-top: auto; margin-bottom: auto; |
.mt-0 | margin-top: 0; |
.mt-1 | margin-top: 0.25rem; /* 4px */ |
.mt-2 | margin-top: 0.5rem; /* 8px */ |
.mt-3 | margin-top: 0.75rem; /* 12px */ |
.mt-4 | margin-top: 1rem; /* 16px */ |
.mt-5 | margin-top: 1.25rem; /* 20px */ |
.mt-6 | margin-top: 1.5rem; /* 24px */ |
.mt-7 | margin-top: 1.75rem; /* 28px */ |
.mt-8 | margin-top: 2rem; /* 32px */ |
.mt-9 | margin-top: 2.25rem; /* 36px */ |
.mt-10 | margin-top: 2.5rem; /* 40px */ |
.mt-11 | margin-top: 2.75rem; /* 44px */ |
.mt-12 | margin-top: 3rem; /* 48px */ |
.mt-14 | margin-top: 3.5rem; /* 56px */ |
.mt-16 | margin-top: 4rem; /* 64px */ |
.mt-20 | margin-top: 5rem; /* 80px */ |
.mt-auto | margin-top: auto; |
.mb-0 | margin-bottom: 0; |
.mb-1 | margin-bottom: 0.25rem; /* 4px */ |
.mb-2 | margin-bottom: 0.5rem; /* 8px */ |
.mb-3 | margin-bottom: 0.75rem; /* 12px */ |
.mb-4 | margin-bottom: 1rem; /* 16px */ |
.mb-5 | margin-bottom: 1.25rem; /* 20px */ |
.mb-6 | margin-bottom: 1.5rem; /* 24px */ |
.mb-7 | margin-bottom: 1.75rem; /* 28px */ |
.mb-8 | margin-bottom: 2rem; /* 32px */ |
.mb-9 | margin-bottom: 2.25rem; /* 36px */ |
.mb-10 | margin-bottom: 2.5rem; /* 40px */ |
.mb-11 | margin-bottom: 2.75rem; /* 44px */ |
.mb-12 | margin-bottom: 3rem; /* 48px */ |
.mb-14 | margin-bottom: 3.5rem; /* 56px */ |
.mb-16 | margin-bottom: 4rem; /* 64px */ |
.mb-20 | margin-bottom: 5rem; /* 80px */ |
.mb-auto | margin-bottom: auto; |
.ms-0 | margin-left: 0; |
.ms-1 | margin-left: 0.25rem; /* 4px */ |
.ms-2 | margin-left: 0.5rem; /* 8px */ |
.ms-3 | margin-left: 0.75rem; /* 12px */ |
.ms-4 | margin-left: 1rem; /* 16px */ |
.ms-5 | margin-left: 1.25rem; /* 20px */ |
.ms-6 | margin-left: 1.5rem; /* 24px */ |
.ms-7 | margin-left: 1.75rem; /* 28px */ |
.ms-8 | margin-left: 2rem; /* 32px */ |
.ms-9 | margin-left: 2.25rem; /* 36px */ |
.ms-10 | margin-left: 2.5rem; /* 40px */ |
.ms-11 | margin-left: 2.75rem; /* 44px */ |
.ms-12 | margin-left: 3rem; /* 48px */ |
.ms-14 | margin-left: 3.5rem; /* 56px */ |
.ms-16 | margin-left: 4rem; /* 64px */ |
.ms-20 | margin-left: 5rem; /* 80px */ |
.ms-auto | margin-left: auto; |
.me-0 | margin-right: 0; |
.me-1 | margin-right: 0.25rem; /* 4px */ |
.me-2 | margin-right: 0.5rem; /* 8px */ |
.me-3 | margin-right: 0.75rem; /* 12px */ |
.me-4 | margin-right: 1rem; /* 16px */ |
.me-5 | margin-right: 1.25rem; /* 20px */ |
.me-6 | margin-right: 1.5rem; /* 24px */ |
.me-7 | margin-right: 1.75rem; /* 28px */ |
.me-8 | margin-right: 2rem; /* 32px */ |
.me-9 | margin-right: 2.25rem; /* 36px */ |
.me-10 | margin-right: 2.5rem; /* 40px */ |
.me-11 | margin-right: 2.75rem; /* 44px */ |
.me-12 | margin-right: 3rem; /* 48px */ |
.me-14 | margin-right: 3.5rem; /* 56px */ |
.me-16 | margin-right: 4rem; /* 64px */ |
.me-20 | margin-right: 5rem; /* 80px */ |
.me-auto | margin-right: auto; |
Assign responsive-friendly margin values to an element or a subset of its sides with shorthand classes. Includes support for individual properties, all properties, and vertical and horizontal properties.
Overview
The margin utilities that apply to all breakpoints, from xs to xxl, have no breakpoint abbreviation in them. This is because those classes are applied from min-width: 0 and up, and thus are not bound by a media query. The remaining breakpoints, however, do include a breakpoint abbreviation.
The classes are named using the format {property}{sides}-{size} for xs and {property}{sides}-{breakpoint}-{size} for sm, md, lg, xl, and xxl.
Where property is m - for classes that set margin
Where sides is one of:
t- for classes that setmargin-topb- for classes that setmargin-bottoms- (start) for classes that setmargin-leftin LTR,margin-rightin RTLe- (end) for classes that setmargin-rightin LTR,margin-leftin RTLx- for classes that set both*-leftand*-righty- for classes that set both*-topand*-bottom- blank - for classes that set a
marginon all 4 sides of the element
Where size is one of:
0- for classes that eliminate themarginby setting it to01- (by default) for classes that set themarginto$spacer * .252- (by default) for classes that set themarginto$spacer * .53- (by default) for classes that set themarginto$spacer4- (by default) for classes that set themarginto$spacer * 1.55- (by default) for classes that set themarginto$spacer * 36- (by extended) for classes that set themarginto$spacer * 47- (by extended) for classes that set themarginto$spacer * 58- (by extended) for classes that set themarginto$spacer * 69- (by extended) for classes that set themarginto$spacer * 710- (by extended) for classes that set themarginto$spacer * 8auto- for classes that set themarginto auto
(You can add more sizes by adding entries to the $spacers Sass map variable.)
Basic usage
Add margin to a single side
Control the margin on one side of an element using the m{t|e|b|s}-{size} utilities.
For example, mt-4 would add 1.5rem of margin to the top of an element, me-3 would add 1rem of margin to the right of an element, mb-5 would add 3rem of margin to the bottom of an element, and ms-2 would add 0.5rem of margin to the left of an element.
<div class="mt-4 ...">mt-4</div>
<div class="me-3 ...">me-3</div>
<div class="mb-5 ...">mb-5</div>
<div class="ms-2 ...">ms-2</div>
Add horizontal margin
Control the horizontal margin of an element using the mx-{size} utilities.
<div class="mx-5 ...">mx-5</div>
Add vertical margin
Control the vertical margin of an element using the my-{size} utilities.
<div class="my-5 ...">my-5</div>
Margin to all sides
Control the margin on all sides of an element using the m-{size} utilities.
<div class="m-5 ...">m-5</div>
Horizontal centering margin
Additionally, Bootstrap also includes an .mx-auto class for horizontally centering fixed-width block level content—that is, content that has display: block and a width set—by setting the horizontal margins to auto.
<div class="mx-auto ...">Centered element</div>
Right align margin
Control the righ-align margin of an element using the ms-auto utilities.
<div class="d-flex gap-4">
<div>01</div>
<div>02</div>
<div class="ms-auto">03</div>
<div>04</div>
<div>05</div>
</div>
Using negative values
In CSS, margin properties can utilize negative values (padding cannot). These negative margins are enabled by default in FastBootstrap, but can be disabled in Sass by setting $enable-negative-margins: false.
The syntax is nearly the same as the default, positive margin utilities, but with the addition of n before the requested size by the format {property}{sides}-n{size}.
<div class="bd-w-36 bd-h-16 ..."></div>
<div class="mt-n5">mt-n5</div>
Breakpoints and media queries
All margin utilities that supports responsive at specific breakpoints, using the following format {property}{sides}-{breakpoint}-{size} for xs, sm, md, lg, xl, and xxl.
For example, use my-md-4 to apply the my-4 utility at only medium screen sizes and above, my-3 for xs by default.
<div class="my-3 my-md-4 my-lg-6 ...">my-3 my-md-4 my-lg-6</div>