On this page
margin
Prev: `box-sizing` | Up: box_model | Next: `padding`
Rel: box_model, Box Model & Sizing Guide
Ref: MDN Web Docs — margin
Tags: #public #web #css #properties #box_model #tier/core
Syntax & Overview
margin: 0 auto; /* logical: margin-inline, margin-block */
Outer spacing outside the border edge; vertical block margins collapse in normal flow.
- Initial:
0| Inherited: No | Animatable: Yes
Notes & Best Practices
- Vertical margins collapse in normal block flow (not inside Flexbox or Grid): Prefer
gapon parent containers for sibling spacing andmargin-inline: autofor centering.
Example
.centered-card {
max-inline-size: 36rem;
margin-inline: auto;
margin-block: 2rem;
}
Linked from
Related notes
- tuts/css/properties/box_model/box-sizing Linked here; links to this page; shared tags: #css, #properties, #tier, #web
- tuts/css/properties/box_model/padding Linked here; links to this page; shared tags: #css, #properties, #tier, #web
- tuts/css/properties/box_model Linked here; links to this page; shared tags: #css, #properties, #web
- tuts/css/properties/box_model_and_sizing Linked here; shared tags: #css, #properties, #web
- tuts/css/properties/box_model/aspect-ratio shared tags: #css, #properties, #tier, #web
- tuts/css/properties/box_model/inline-size shared tags: #css, #properties, #tier, #web
- tuts/css/properties/box_model/overflow shared tags: #css, #properties, #tier, #web
- tuts/css/properties/layout/align-items shared tags: #css, #properties, #tier, #web
- tuts/css/properties/layout/display shared tags: #css, #properties, #tier, #web
- tuts/css/properties/layout/flex shared tags: #css, #properties, #tier, #web