Utilities

Spacing

There are a wide range of shorthand responsive margin and padding utility classes to modify an element’s appearance.

Margin and padding

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.

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 one of:

Where sides is one of:

Where size is one of:

Examples

Left and right padding of 3rem
Top and bottom padding of 1.5rem
Left margin of 1.4rem
<div class="px-5">Left and right padding of 3rem</div>

<div class="py-4">Top and bottom padding of 1.5rem</div>

<div class="ml-4">Left margin of 1.4rem</div>

Horizontal centering

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.

Example:

Centered element
<div class="mx-auto" style="width: 200px;">
  Centered element
</div>
Prev Next