---
title: Margins
summary: Use margin utilities to control the space between elements.
description: Control the space between elements with margin utilities.
related: [/ui/utilities/vertical-align]
---
import Example from '@components/Example.astro';
Margin utilities set the space around an element with a class, so you don't write CSS for spacing. Every direction uses the same sizes, listed in the table below.
## Margin size
In the table below you can see the available margin sizes.
Name|Value
-|-
0|0
1|0.25rem
2|0.5rem
3|1rem
4|1.5rem
5|2rem
6|3rem
7|5rem
8|8rem
## Margin
`.m-*` sets the margin on all four sides.
## Start margin
`ms-*` sets the margin on the start side, which is the left in a left-to-right layout.
```html
...
```
## End margin
`me-*` sets the margin on the end side, which is the right in a left-to-right layout.
```html
...
```
## Top margin
`mt-*` sets the margin above an element, for example between stacked sections.
```html
...
```
## Bottom margin
`mb-*` sets the margin below an element.
```html
...
```
## Horizontal margin
`mx-*` sets the start and end margins at once.
```html
...
```
## Vertical margin
`my-*` sets the top and bottom margins at once.
```html
...
```
## Horizontal centering
`.mx-auto` centers a block element that has a width, by setting both horizontal margins to `auto`.
```html
...
```
## Gap
`.gap-*` sets the space between the children of a grid or flex container, with the same sizes as the margins.
```html
...
```
```html example
Grid item 1
Grid item 2
Grid item 3
```
## Accessibility
- Spacing carries grouping. Items that belong together should sit closer than items that do not, and that grouping has to exist in the markup too - a list, a `fieldset`, a section.
- Do not replace a heading with a large margin. Whitespace is invisible to a screen reader.
- Space between interactive controls keeps them apart for anyone with a shaky hand. Keep touch targets at least 24 by 24 pixels with a gap between them.
- The margin utilities are direction aware, so `ms-*` and `me-*` follow the text direction, while `ml-*` and `mr-*` do not. Prefer the logical ones in a layout that has to work in RTL.