Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Box Model and Sizing

The margin-bottom property

Reference for the CSS margin-bottom property: syntax, values, percentages, margin collapsing with the next element, examples and browser support.

The margin-bottom property sets the space below an element's border edge. It keeps the next sibling at a distance, or separates the element from the bottom of its container's content.

CSS
p {
  margin-bottom: 1em;
}

Try it

Space below a box

Syntax

CSS
margin-bottom: <length> | <percentage> | auto
  • Initial value: 0
  • Applies to: all elements except internal table display types; no effect on non-replaced inline elements
  • Inherited: no
  • Percentages: relative to the width of the containing block
  • Animatable: yes
  • Computed value: the percentage as specified or the absolute length; auto stays auto

Values

Value Description
<length> A fixed size such as 1.5rem. Negative values pull the next element upward so it overlaps.
<percentage> A share of the containing block's width.
auto Computes to 0 in normal block flow. In a flex column, margin-bottom: auto pushes the item to the top and leaves the free space below it.

Usage notes

  • Collapsing. The bottom margin of a block merges with the top margin of the next block, and the larger one wins. If the last child has a bottom margin and its parent has no padding, border or height, that margin can collapse through the parent and appear below it.
  • Styling one-sided rhythm. Setting only margin-bottom on every element leaves a stray gap after the last one. Use :last-child { margin-bottom: 0 }, or space with gap or a * + * rule.
  • Inline elements ignore vertical margins; use display: inline-block or block.
  • Text descenders. A small gap under an image comes from it being inline and sitting on the text baseline, not from margins. Set display: block on the image to remove it.

Browser support

Supported in every browser.