CSS margin-block Property

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

Definition and Usage

The margin-block property is a shorthand for margin-block-start and margin-block-end. It sets outer spacing on the block axis.

In a horizontal writing mode (the usual default), that maps to top and bottom — like margin-top / margin-bottom. With a vertical writing-mode, it can map to the physical left/right sides instead. It is not inherited. Each side starts at 0.

Baseline · Widely available.

Not deprecated. Cross-browser since about April 2021. Prefer it over physical top/bottom when writing mode may change.

Logical tip.

Pair with margin-inline for the other axis. Together they replace the classic four physical margins in writing-mode-aware layouts.

CSS Syntax

syntax.css
margin-block: [ <length> | <percentage> | auto ]{1,2} | initial | inherit;

1 value = both block-start and block-end. 2 values = block-start, then block-end.

Property Values

ValueDescriptionTry it
One lengthSame margin on block-start and block-end, such as 1remTry it
Two valuesStart then end, such as 0.5rem 1.5remTry it
autoBrowser chooses the block-axis margin (same idea as physical auto)Try it
<percentage>Percent of the containing block (layout-dependent, often its width)Try it
With writing-modeShows how block margins map when text flows verticallyTry it
initialResets both sides to 0Try it
inheritInherits from the parent elementTry it

How to Use margin-block

Think in block-start / block-end instead of top / bottom.

  1. Decide the block-axis spacing (before and after the element in the writing flow).
  2. Set margin-block with one value (both sides) or two (start, end).
  3. Use margin-inline if you also need the inline axis.
  4. Test with writing-mode if the page may switch orientation.
In horizontal-tbUsually maps to
margin-block-startmargin-top
margin-block-endmargin-bottom
margin-block: 1remLike margin-top and margin-bottom: 1rem

Live Preview

The middle (amber) box is the target. Change margin-block in a horizontal writing mode.

In this preview, block-start is top and block-end is bottom.

Boxes
Above
Target
Below

margin-block: 0

CSS Examples

Each snippet shows only margin-block (plus writing-mode when needed). Use Try It Yourself for a live editor.

Example 1 — Same Value Both Sides

One value sets block-start and block-end together.

CSS
<style>
  .box {
    margin-block: 1rem;
  }
</style>

<div class="box">Target</div>
Try It Yourself

How It Works

  1. One length. 1rem applies to both block-start and block-end.
  2. Horizontal default. That usually means top and bottom get 1rem.
  3. Neighbors move. Space appears above and below the target box.
  4. Same as two equal longhands. Equivalent to setting start and end both to 1rem.

Example 2 — Different Start and End

Two values set block-start, then block-end.

CSS
<style>
  .box {
    margin-block: 0.5rem 1.5rem;
  }
</style>

<div class="box">Target</div>
Try It Yourself

How It Works

  1. First value. 0.5rem is block-start (usually top).
  2. Second value. 1.5rem is block-end (usually bottom).
  3. Asymmetric spacing. More space appears after the box than before it.
  4. Longhand option. Same as margin-block-start / margin-block-end separately.

Example 3 — Vertical Writing Mode

Block margins follow the writing mode, not always top/bottom.

CSS
<style>
  .stack {
    writing-mode: vertical-rl;
  }

  .box {
    margin-block: 1rem;
  }
</style>

<div class="stack">
  <div class="box">Target</div>
</div>
Try It Yourself

How It Works

  1. Change the flow. writing-mode: vertical-rl makes lines run vertically.
  2. Keep logical margin. margin-block still means start/end of the block axis.
  3. Physical sides change. The same rule may now affect left/right instead of top/bottom.
  4. Why it matters. One rule stays correct when orientation changes.

Edge Cases & Pitfalls

Logical names are easy to mix up with physical top/bottom.

mapping

Not always top and bottom

In vertical writing modes, block-start/end can map to physical left/right. Check writing-mode before debugging.

collapse

Block margins can still collapse

In normal flow, adjacent block-axis margins may collapse just like classic top/bottom margins.

shorthand

Physical margin can override

A later margin shorthand sets all four physical sides and can wipe logical longhands depending on cascade order.

support

Newer than classic margin

Safe in modern browsers (about 2021+). For very old IE-only targets, use physical margin-top / margin-bottom.

pair

Remember the inline axis

margin-block does not set left/right in horizontal mode. Use margin-inline for that axis.

Browser Support

margin-block is a browser CSS property (logical box model). Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

margin-block

Supported in modern browsers since about April 2021. Part of CSS Logical Properties and Values.

95% Modern support
Google Chrome 87+
Full support
Mozilla Firefox 66+
Full support
Apple Safari 14.1+
Full support
Microsoft Edge 87+
Full support
Opera 73+
Full support
Samsung Internet 14+
Full support
Internet Explorer —
No support
margin-block Modern browsers

Bottom line: Safe for modern sites. Fall back to margin-top/margin-bottom only if you must support Internet Explorer. It is not a runtime API.

Key Takeaways

  • Role: shorthand for block-start and block-end outer margins.
  • Logical: follows writing mode — not locked to physical top/bottom.
  • Values: one for both sides, or two for start then end.
  • Pair: use margin-inline for the other axis.

One line: margin-block sets start/end margins on the block axis — writing-mode aware spacing.

Frequently Asked Questions

It is a shorthand for margin-block-start and margin-block-end. It sets outer spacing on the block axis, which maps to physical sides based on writing mode.
Each longhand defaults to 0, so there is no block-axis margin until you set one.
margin-top and margin-bottom always mean physical top and bottom. margin-block follows the writing mode, so in horizontal text it is usually top/bottom, and in vertical text it can map to left/right.
Yes. One value sets both start and end. Two values set start, then end.
Use it when vertical (block-axis) spacing should stay correct if writing-mode or direction changes, especially in multilingual layouts.
It is Baseline and widely available in modern browsers since about April 2021. It is a browser CSS property, not a Node.js feature.

Next: margin-block-end

Learn the longhand for the block-end outer margin.

margin-block-end 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