CSS margin-bottom Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The margin-bottom property sets the margin area on the bottom of an element. A positive value moves neighbors farther away; a negative value pulls them closer.

It is part of the box model (outside the border), is not inherited, and has no effect on non-replaced inline elements such as <span>. Prefer margin-block-end when you want spacing that follows writing mode.

Baseline · Widely available.

Not deprecated. Core length, percentage, and auto values work across modern browsers.

CSS Syntax

syntax.css
margin-bottom: <length> | <percentage> | auto | inherit;

Example: margin-bottom: 1.5rem;. Values may be positive, zero, or negative.

Property Values

ValueDescriptionTry it
<length>Fixed size such as 16px or 1emTry it
<percentage>Relative to the containing block’s width (inline size)Try it
autoBrowser chooses a used value (often 0 for bottom alone)Try it
Negative lengthPulls following content closer or into the elementTry it
0 / initialNo bottom margin (initial value is 0)Try it
inheritTakes the parent’s margin-bottomTry it

How to Use margin-bottom

Use it to space a block away from whatever comes after it.

  1. Select the element that needs space underneath.
  2. Set a length (1rem, 24px) or a percentage of the container width.
  3. Prefer gap on flex/grid parents when spacing many siblings evenly.
  4. Watch for vertical margin collapse between stacked blocks.
PieceRequired?Role
Block or replaced boxTypicalInline non-replaced elements ignore margin-bottom
Length or %Yes (or auto)Sets the bottom outer space
InheritedNoSet on each element that needs it
Following contentTo see itThe gap appears before the next box in normal flow

Live Preview

Change margin-bottom on the yellow box and watch the space before the next box.

Percentages are based on the container width, not its height.

Stacked boxes
Target
Next

margin-bottom: 24px

CSS Examples

Each snippet focuses on margin-bottom. Use Try It Yourself for a live editor.

Example 1 — Length Spacing

Add a fixed gap below a box.

CSS
<style>
  .card {
    margin-bottom: 24px;
  }
</style>

<div class="card">Card</div>
<div>Next</div>
Try It Yourself

How It Works

  1. Target the first box. The rule applies to .card.
  2. Set 24px. Outer space appears below its border.
  3. Next box moves down. The following element starts after that gap.
  4. Not padding. The space is outside the border, not inside the content box.

Example 2 — Percentage

Size the bottom margin from the container width.

CSS
<style>
  .box {
    margin-bottom: 10%;
  }
</style>

<div class="box">Box</div>
<div>Next</div>
Try It Yourself

How It Works

  1. Percent of width. Vertical margin percentages use the containing block’s inline size.
  2. Wider parent → larger gap. The bottom margin scales with container width.
  3. Not based on height. A common surprise for beginners.
  4. Try resizing the editor pane to see the gap change.

Example 3 — Negative Margin

Pull the next box closer (or overlap).

CSS
<style>
  .pull {
    margin-bottom: -12px;
  }
</style>

<div class="pull">Pull</div>
<div>Closer</div>
Try It Yourself

How It Works

  1. Negative length. The bottom margin becomes less than zero.
  2. Next box moves up. Content can overlap if the value is large enough.
  3. Use sparingly. Prefer padding, gap, or positive margins for everyday layout.
  4. Check stacking and click targets when boxes overlap.

Edge Cases & Pitfalls

If the gap looks wrong or missing, check these first.

collapse

Vertical margins can collapse

A block’s margin-bottom and the next block’s margin-top may combine into one gap — often the larger value, not the sum.

inline

No effect on non-replaced inline

MDN: margin-bottom does not affect elements like <span>. Use a block, inline-block, or flex/grid item instead.

percent

% is based on width

Even for bottom margin, percentages resolve against the containing block’s inline size (width in horizontal writing modes).

vs

margin-bottom vs padding-bottom

Use padding-bottom for inner space (backgrounds extend into padding). Use margin for space between separate boxes.

logical

Physical bottom vs block-end

For multilingual or vertical layouts, prefer margin-block-end so spacing follows writing mode.

Browser Support

margin-bottom is a browser CSS property for the box model. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

margin-bottom

Length, percentage, and auto values work in all modern browsers and older engines.

99% Browser support
Google Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Opera All modern versions
Full support
Samsung Internet Supported
Full support
Internet Explorer Supported
Full support
margin-bottom Widely supported

Bottom line: Safe for everyday vertical spacing. Remember collapse and the %/width rule. It is not a runtime API.

Key Takeaways

  • Role: outer space below an element’s border.
  • Initial: 0. Not inherited.
  • Percentages use containing-block width.
  • Collapse can merge adjacent vertical margins.

One line: margin-bottom pushes space under a box — outside the border, before the next element.

Frequently Asked Questions

It sets the outer space below an element, outside its border. A positive value pushes following content down; a negative value pulls neighbors closer.
The initial value is 0. There is no bottom margin until you set one.
margin-bottom is outside the border, between elements. padding-bottom is inside the border, between the border and the content.
margin-bottom always targets the physical bottom edge. margin-block-end follows writing mode, so it maps to the block-end side in vertical or RTL layouts.
Yes. Adjacent vertical margins between block boxes can collapse into one. The used gap is often the larger of the two margins.
It is Baseline Widely available. It is a browser CSS box-model property, not a Node.js runtime feature.

Next: margin-inline

Set both inline-start and inline-end margins together.

margin-inline tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful