--- title: Margin path: utilities/margin status: Stable source: 'https://github.com/primer/css/blob/main/src/utilities/margin.scss' bundle: utilities --- Margin utilities are based on a global [spacing scale](/support/spacing) which helps keep horizontal and vertical spacing consistent. These utilities help us reduce the amount of custom CSS that share the same properties, and allows to achieve many different page layouts using the same styles. ## Naming convention Since margin utilities have many variations and will be used in many places, we use a shorthand naming convention to help keep class names succinct. | Shorthand | Description | | --- | --- | | m | margin | | t | top | | r | right | | b | bottom | | l | left | | x | horizontal, left & right | | y | vertical, top & bottom | | 0 | 0 | | 1 | 4px | | 2 | 8px | | 3 | 16px | | 4 | 24px | | 5 | 32px | | 6 | 40px | ## Uniform margins Use uniform spacing utilities to apply equal margin to all sides of an element. These utilities can change or override default margins, and can be used with a spacing scale from 0-6. ```html live
.m-0
.m-1
.m-2
.m-3
.m-4
.m-5
.m-6
``` ## Directional margins Use directional utilities to apply margin to an individual side, or the X and Y axis of an element. Directional utilities can change or override default margins, and can be used with a spacing scale of 0-6. ```html live
.mt-3
.mr-3
.mb-3
.ml-3
.mx-3
.my-3
``` ## Center elements Use `mx-auto`to center block elements with a set width. ```html live
.mx-auto
``` ## Reset margins Reset margins built into typography elements or other components with `m-0`, `mt-0`, `mr-0`, `mb-0`, `ml-0`, `mx-0`, and `my-0`. ```html live

No bottom margin on this paragraph.

``` ## Responsive margins All margin utilities can be adjusted per [breakpoint](/objects/grid#breakpoints) using the following formula: `m[direction]-[breakpoint]-[spacer]`. Each responsive style is applied to the specified breakpoint and up. ```html live
.mx-sm-2 .mx-md-4
``` ## Negative margins You can add negative margins to the top, right, bottom, or left of an item by adding a negative margin utility. The formula for this is: `m[direction]-n[spacer]`. This also works responsively, with the following formula: `m[direction]-[breakpoint]-n[spacer]`. ```html live
.m-3 .ml-n4 .ml-md-n6
```