Widely available Essential for layout spacing, though shared spacing tokens often scale better than many one-off values.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
1
12
1
1
18
1
Other

The margin-bottom CSS property sets the margin area on the bottom of an element. A positive value places it farther from its neighbors, while a negative value places it closer.

1
12
1
1
18
1
CSS property
auto
1
12
1
1
18
1
Other

The margin-left CSS property sets the margin area on the left side of an element. A positive value places it farther from its neighbors, while a negative value places it closer.

1
12
1
1
18
1
CSS property
auto
1
12
1
1
18
1
Other

The margin-right CSS property sets the margin area on the right side of an element. A positive value places it farther from its neighbors, while a negative value places it closer.

1
12
1
1
18
1
CSS property
auto
1
12
1
1
18
1
Other

The margin-top CSS property sets the margin area on the top of an element. A positive value places it farther from its neighbors, while a negative value places it closer.

1
12
1
1
18
1
CSS property
auto
1
12
1
1
18
1
auto
1
12
1
1
18
1
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 1 item(s)
Implementation note
  • The `auto` value is not supported in quirks mode.
Notes 1 item(s)
Implementation note
  • The `auto` value is not supported in quirks mode.
Notes 1 item(s)
Implementation note
  • The `auto` value is not supported in quirks mode.
Notes 1 item(s)
Implementation note
  • The `auto` value is not supported in quirks mode.
Notes 1 item(s)
Implementation note
  • The `auto` value is not supported in quirks mode.

Syntax

CSS
.container {
  margin: 0 auto;
}
.card {
  margin: 16px;
}
.section {
  margin-block: 2rem;
}

Live demo

Margin: 0 Auto(center placement)

CSS Margin: 0 auto(center placement) demo.

PreviewFullscreen

Margin: 16px(alldirection)

CSS Margin: 16px(alldirection) demo.

PreviewFullscreen

Margin-block(vertical. only)

CSS Margin-block(vertical. only) demo.

PreviewFullscreen

Use cases

  • Vertical rhythm

    Space sections, paragraphs, and cards consistently so long pages remain readable.

  • Outer separation

    Create distance between neighboring components without altering their internal padding.

Cautions

  • Margin collapsing and negative margins can produce effects that are surprising if not understood clearly.
  • Ad hoc margin values tend to create inconsistent spacing across a large system.

Accessibility

  • Consistent spacing improves scanability and reduces visual crowding for many users.