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.