# Spacing

###### Bootstrap includes a wide range of shorthand responsive margin and padding utility classes to modify an element’s appearance.

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`.

We have further added quick margin and padding options for by using gutter space variable `.m-g`, margin bottom gutter `.mb-g`. Padding gutter can be adding by using `.p-g` modifier. The `*-g` will change based on the gutter variable.

## Default Panel

Spacing 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 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-start` or `padding-start`
- `r` - for classes that set `margin-end` or `padding-end`
- `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`
- `auto` - for classes that set the `margin` to auto

Example padding:

.p-2 .p-sm-3 .p-md-4 .p-lg-5 .p-xl-6 .p-xxl-7
.p-1 .p-sm-2 .p-md-3 .p-lg-4 .p-xl-5 .p-xxl-6
.p-0 .p-sm-1 .p-md-2 .p-lg-3 .p-xl-4 .p-xxl-5
.p-3 .p-sm-0 .p-md-1 .p-lg-2 .p-xl-3 .p-xxl-4
.p-4 .p-sm-4 .p-md-0 .p-lg-1 .p-xl-2 .p-xxl-3
.p-5 .p-sm-6 .p-md-3 .p-lg-0 .p-xl-1 .p-xxl-2
.p-6 .p-sm-5 .p-md-5 .p-lg-6 .p-xl-0 .p-xxl-1

## Horizontal centering

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`.

Centered element

## Negative margin

The syntax is nearly the same as the default, positive margin utilities, but with the addition of `n` before the requested size.

Here’s an example of customizing the Bootstrap grid at the medium (`md`) breakpoint and above. We’ve increased the `.col` padding with `.px-md-5` and then counteracted that with `.mx-md-n5` on the parent `.row`.

Custom column padding
Custom column padding

## Margin examples

Margin specific viewports example
*-xs-* <576px
*-sm-* ≥576px
*-md-* ≥768px
*-lg-* ≥992px
*-xl-* ≥1200px
*-xxl-* ≥1400px
.ms-1 .ms-sm-2 .ms-md-3 .ms-lg-4 .ms-xl-5 .ms-xxl-6
.mx-1 .mx-sm-2 .mx-md-3 .mx-lg-4 .mx-xl-5 .mx-xxl-6
.my-1 .my-sm-2 .my-md-3 .my-lg-4 .my-xl-5 .my-xxl-6
.m-1 .m-sm-2 .m-md-3 .m-lg-4 .m-xl-5 .m-xxl-6

#### Hi Sunny,

how can I help you today?
Analyze my data

Create a new report

Summarize my Calendar

App Builder
Unlock limitless design potential with 16+ layout combinations and extensive customization options—tailor your dashboard to fit your exact needs.
Header position fixed
Navigation full height
Navigation position fixed
Navigation collapsed
Navigation Minified
Dark Navigation
Colorblind Mode
High Contrast Mode