Spacing
Space includes a wide range of shorthand responsive margin and padding utility classes to modify an element's appearance.
How it works
Assign responsive-friendly margin or padding 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. Classes are built from a default Sass map ranging from .25rem to 3rem.
Notation
Spacing utilities that apply to all breakpoints, from xs to xl, 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, and xl.
Where property is one of:
m- for classes that setmarginp- for classes that setpadding
Where sides is one of:
t- for classes that setmargin-toporpadding-topb- for classes that setmargin-bottomorpadding-bottoml- for classes that setmargin-leftorpadding-leftr- for classes that setmargin-rightorpadding-rightx- for classes that set both*-leftand*-righty- for classes that set both*-topand*-bottom- blank - for classes that set a
marginorpaddingon all 4 sides of the element
Where size is one of:
0- for classes that eliminate themarginorpaddingby setting it to01- (by default) for classes that set themarginorpaddingto$spacer * .252- (by default) for classes that set themarginorpaddingto$spacer * .53- (by default) for classes that set themarginorpaddingto$spacer4- (by default) for classes that set themarginorpaddingto$spacer * 1.55- (by default) for classes that set themarginorpaddingto$spacer * 26- (by default) for classes that set themarginorpaddingto$spacer * 2.57- (by default) for classes that set themarginorpaddingto$spacer * 38- (by default) for classes that set themarginorpaddingto$spacer * 3.59- (by default) for classes that set themarginorpaddingto$spacer * 4auto- for classes that set themarginto auto
(You can add more sizes by adding entries to the $spacers Sass map variable via: assets/include/scss/vendor/bootstrap/_custom.bootstrap.variables.scss.)
Offset spacings
Space includes several offset classes, like:
<div class="ml-n3">.ml-n3</div>
<div class="mr-n3">.mr-n3</div>
<div class="mt-offset-5">.mt-offset-5</div>
<div class="mt-n1">.mt-n1</div>
<div class="mt-n9">.mt-n9</div>
<div class="mb-n9">.mb-n9</div>
<div class="mb-offset-14">.mb-offset-14</div>
Gutters
As well as gutters.
<div class="mx-gutters-1">.mx-gutters-1</div>
<div class="mx-gutters-2">.mx-gutters-2</div>
Examples
Here are some representative examples of these classes:
.mt-0 {
margin-top: 0 !important;
}
.ml-1 {
margin-left: ($spacer * .25) !important;
}
.px-2 {
left: ($spacer * .5) !important;
padding-right: ($spacer * .5) !important;
}
.p-3 {
padding: $spacer !important;
}
Horizontal centering
Additionally, Space 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 bg-primary text-white" style="width: 200px;">
Centered element
</div>
Vertical padding spacings
Additionally, Space also includes $space-1 to $space-5 spacing classes.
| Class names | Padding top value | Padding bottom value |
|---|---|---|
.space-0 |
0rem | 0rem |
.space-top-0 |
0rem | |
.space-bottom-0 |
0rem | |
.space-1 |
2rem | 2rem |
.space-1-top |
2rem | |
.space-1-bottom |
2rem | |
.space-2 |
4.0625rem | 4.0625rem |
.space-2-top |
4.0625rem | |
.space-2-bottom |
4.0625rem | |
.space-3 |
8.125rem | 8.125rem |
.space-3-top |
8.125rem | |
.space-3-bottom |
8.125rem | |
.space-4 |
12.5rem | 12.5rem |
.space-4-top |
12.5rem | |
.space-4-bottom |
12.5rem | |
.space-5 |
15rem | 15rem |
.space-5-top |
15rem | |
.space-5-bottom |
15rem |
Vertical responsive padding classes
| Medium devices (sm) | Padding top value | Padding bottom value |
|---|---|---|
.space-3--sm |
8.125rem | 8.125rem |
.space-3-bottom--sm |
8.125rem | |
.space-4-top--sm |
12.5rem | |
.space-5--sm |
15rem | 15rem |
| Medium devices (md) | Padding top value | Padding bottom value |
|---|---|---|
.space-2-bottom-0--md |
0rem | |
.space-3--md |
8.125rem | 8.125rem |
.space-3-top--md |
8.125rem | |
.space-3-bottom--md |
8.125rem | |
.space-4--md |
12.5rem | 12.5rem |
.space-4-top--md |
12.5rem | |
.space-5--md |
15rem | 15rem |
.space-5-top-md |
15rem |
| Large devices (lg) | Padding top value | Padding bottom value |
|---|---|---|
.space-0--lg |
0rem | 0rem |
.space-0-top--lg |
0rem | |
.space-0-bottom--lg |
0rem | |
.space-1--lg |
2rem | 2rem |
.space-3--lg |
8.125rem | 8.125rem |
.space-3-top--lg |
8.125rem | |
.space-3-bottom--lg |
8.125rem | |
.space-4--lg |
12.5rem | 12.5rem |
.space-4-top--lg |
12.5rem | |
.space-4-bottom--lg |
12.5rem | |
.space-5--lg |
15rem | 15rem |
.space-5-top-lg |
15rem |
| Medium devices (xl) | Padding top value | Padding bottom value |
|---|---|---|
.space-3-bottom--xl |
8.125rem | |
.space-4-top--xl |
12.5rem |
Important
Space does not include all classes, but includes only used classes to reduce the size of CSS files. However, you can add more sizes by adding entries to the $space-* Sass map variable via: assets/include/scss/_variables.scss.