CSS Portal

CSS margin-bottom Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The margin-bottom property controls the space outside an element’s border on its lower edge. It is one side of the overall box-model margin and is commonly used to separate stacked elements vertically, creating whitespace that other elements can occupy. Because this space is outside the element’s border, it is transparent and will reveal the background of the parent or the page behind it rather than the element’s own background; it is also conceptually part of the broader margin concept used to control spacing on all four sides.

In a normal flow of block layout, vertical spacing produced by margin-bottom can interact with the top margin of the element that follows; those vertical margins may collapse into a single margin rather than add together. That collapsing behavior has a few well-known exceptions: it does not happen when there is border or padding between the margins (so adding padding or a border prevents collapse), and it behaves differently for out-of-flow elements. Creating a block formatting context will also stop vertical margin collapsing, which can be triggered by certain layout conditions such as specific overflow settings, certain display values, or floating an element with float.

How margin-bottom affects layout depends on an element’s formatting context and positioning. For floated or absolutely positioned elements the margin participates in that element’s placement but does not collapse with neighboring in-flow block margins; out-of-flow elements are effectively removed from normal flow so their margins won’t push other blocks in the usual way. For inline-level elements vertical margins behave differently than on blocks: they generally don’t create the same external push between lines the way block-level margins do, and some layout modes (for example when an element is part of a flex formatting context created by certain display values) interact with margins in ways that are specific to that layout mode. Finally, because margin-bottom is purely spacing outside the border, it is a common and powerful tool for visual rhythm and separation in responsive layouts, but its interactions with collapse and formatting contexts should be kept in mind when predictable spacing is required—especially when mixing floats, positioned elements, and different display types.

Definition

Initial value
0
Applies to
All elements
Inherited
No
Computed value
As specified, but with relative lengths converted into absolute pixel values.
Animatable
Yes
JavaScript syntax
object.style.marginBottom

Interactive Demo

Margin Bottom Example

Syntax

margin-bottom: <length> | <percentage> | auto

Values

  • <length>Specifies a fixed length, using any standard CSS length units. Negative Values are allowed.
  • <percentage>A percentage always relative to the width of the containing block.
  • inherit

Example

<div class="wrapper">
<h2>CSS margin-bottom example</h2>
<div class="card with-margin">This box has margin-bottom: 24px;</div>
<div class="card">This sibling box sits below the first one.</div>
</div>
.wrapper {
    max-width: 480px;
    margin: 40px auto;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}

h2 {
    margin: 0 0 16px 0;
    font-size: 18px;
}

.card {
    background: #f3f4f6;
    padding: 16px;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.with-margin {
    margin-bottom: 24px;
}

Browser Support

The following information will show you the current browser support for the CSS margin-bottom property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!