Home·CSS properties

margin

Box and spacing

The space outside the box; top and bottom margins collapse into one.

How to write itmargin: 0;
Common values0, auto, 1rem, 0 auto
InheritedNo — it stops at this element
Sets all ofmargin-top, margin-right, margin-bottom, margin-left
CategoryBox and spacing

How to read this

  • An inherited property only needs writing once on the parent — every child picks it up. Most text properties work this way.
  • A shorthand resets whatever you leave out. Writing background: red alone also wipes a background image you set earlier.
  • When rules collide, the more specific selector wins; only when specificity ties does source order decide.
  • Animate transform and opacity for smoothness. Changing width or top forces the layout to be recalculated.

Frequently asked questions

Q. What is the CSS margin property?

The space outside the box; top and bottom margins collapse into one.

Q. How do you write margin?

As margin: 0; Common values include 0, auto, 1rem, 0 auto.

Q. Is margin inherited?

No. It applies only where you write it, so each element needs its own declaration.

Q. What does the margin shorthand set?

margin-top, margin-right, margin-bottom, margin-left — and anything you leave out resets to its default.

Properties in the same group

Reference docs