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 set margin
  • p - for classes that set padding

Where sides is one of:

  • t - for classes that set margin-top or padding-top
  • b - for classes that set margin-bottom or padding-bottom
  • l - for classes that set margin-left or padding-left
  • r - for classes that set margin-right or padding-right
  • x - for classes that set both *-left and *-right
  • y - for classes that set both *-top and *-bottom
  • blank - for classes that set a margin or padding on all 4 sides of the element

Where size is one of:

  • 0 - for classes that eliminate the margin or padding by setting it to 0
  • 1 - (by default) for classes that set the margin or padding to $spacer * .25
  • 2 - (by default) for classes that set the margin or padding to $spacer * .5
  • 3 - (by default) for classes that set the margin or padding to $spacer
  • 4 - (by default) for classes that set the margin or padding to $spacer * 1.5
  • 5 - (by default) for classes that set the margin or padding to $spacer * 2
  • 6 - (by default) for classes that set the margin or padding to $spacer * 2.5
  • 7 - (by default) for classes that set the margin or padding to $spacer * 3
  • 8 - (by default) for classes that set the margin or padding to $spacer * 3.5
  • 9 - (by default) for classes that set the margin or padding to $spacer * 4
  • auto - for classes that set the margin to 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-offset-3">.ml-offset-3</div>
              <div class="mt-offset-5">.mt-offset-5</div>
              <div class="mt-offset-1">.mt-offset-1</div>
              <div class="mt-offset-9">.mt-offset-9</div>
              <div class="mb-offset-9">.mb-offset-9</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.

Centered element
            
              <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-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.