Skip to the page
css reference · the box model

CSS margin

type
property
applies to
any element
inherits
no
common values
0, auto, 16px, 1rem, 1em

Where it goes

On any box that needs room from its neighbors.

Example

.card {
  margin: 0 auto 24px;
  max-width: 600px;
}

Common mistakes

  • Expecting two stacked margins to add up. Between stacked boxes, only the larger one counts.
  • Using margin: auto to center a box that has no width set. Auto centering only works once the box has a width.

Related

Updated 24 October 2026. Practice it in the css route, or read more on MDN.