CSS margin-block Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout & Logical Properties

What You’ll Learn

The margin-block property sets outer spacing on the block axis using logical sides instead of physical top and bottom.

01

Block Axis

Start and end.

02

Shorthand

1 or 2 values.

03

Writing Mode

Adapts to flow.

04

Logical

Not top/bottom.

05

Longhand

start + end.

06

Default 0

No spacing.

Introduction

The margin-block property in CSS is a shorthand property that allows you to set the margin on the block start and block end sides of an element. In a block-level context, the block start refers to the top, and the block end refers to the bottom. However, in a writing mode where text flows vertically, these terms adapt accordingly.

This property provides a convenient way to control vertical margins in layouts, respecting the text direction and writing mode of the document.

Definition and Usage

Apply margin-block when you want block-axis spacing that stays correct in multilingual layouts, RTL pages, or vertical writing modes. Use one value for equal block-start and block-end margins, or two values for different spacing on each side.

💡
Beginner Tip

In normal horizontal English pages, margin-block: 20px 10px behaves like margin-top: 20px and margin-bottom: 10px. The difference appears when writing mode changes.

📝 Syntax

The syntax for the margin-block property allows you to specify values for both the block start and block end margins.

syntax.css
element {
  margin-block: <margin-start> <margin-end>;
}
  • <margin-start> — The margin for the block start side (top in horizontal writing modes).
  • <margin-end> — The margin for the block end side (bottom in horizontal writing modes).

If only one value is provided, it applies to both the block start and block end sides.

Basic Example

margin-block.css
p {
  margin-block: 20px 10px;
}

⚡ Quick Reference

QuestionAnswer
Initial value0
Applies toAll elements except table display types that use separate border model
InheritedNo
AnimatableYes, as a length
Longhand propertiesmargin-block-start, margin-block-end

💎 Property Values

ValueExampleMeaning
Lengthmargin-block: 20px 10px;Fixed margin in px, em, rem, etc.
Percentagemargin-block: 5%;Margin as a percentage of the containing block width
automargin-block: auto;Browser calculates the margin
inheritmargin-block: inherit;Inherits the margin value from the parent element
initialmargin-block: initial;Sets the property to its default value (0)
unsetmargin-block: unset;Resets to inherit or initial depending on context
block-start block-end

🎯 Default Value

The default value for the margin-block property is 0, meaning there is no margin applied unless specified otherwise. You can override it with one or two values, or with the longhand properties margin-block-start and margin-block-end.

👀 Live Preview

A box with unequal block-start and block-end margins inside a dashed container:

margin-block: 1.25rem 0.75rem

Examples Gallery

Set different block-start and block-end margins, use a single value, see writing-mode behavior, and compare with longhand properties.

🔢 Block-Axis Spacing

Start with the reference example — set different margins on block start and block end.

Example 1 — Two-Value margin-block

Set a margin of 20px at the top and 10px at the bottom of a paragraph element.

margin-block.html
<style>
  p {
    margin-block: 20px 10px;
  }
</style>

<p>This paragraph has a margin of 20px at the top and 10px at the bottom.</p>
Try It Yourself

How It Works

The first value applies to block-start; the second to block-end. In horizontal writing, that is top and bottom spacing.

Example 2 — Single Value

One value applies equal margin on both block sides.

margin-block-single.css
.section {
  margin-block: 1.5rem;
  padding: 1rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
}
Try It Yourself

How It Works

margin-block: 1.5rem is shorthand for 1.5rem on both block-start and block-end.

📈 Writing Mode & Longhand

See why logical margins matter when text flow changes, and how longhand properties map to the shorthand.

Example 3 — Writing Mode Adaptation

The same margin-block rule follows the block axis when writing mode changes.

margin-block-writing.css
.box {
  margin-block: 1rem 0.5rem;
  padding: 0.75rem;
  background: #eff6ff;
}

.vertical {
  writing-mode: vertical-rl;
}

Horizontal writing

Block axis is vertical

Vertical writing

Block axis is horizontal
Try It Yourself

How It Works

Logical properties follow the block axis, not fixed screen directions. That keeps spacing predictable in international layouts.

Example 4 — Longhand Equivalent

These two rules produce the same result in horizontal writing:

margin-block-longhand.css
/* Shorthand */
.card {
  margin-block: 2rem 1rem;
}

/* Longhand equivalent */
.card {
  margin-block-start: 2rem;
  margin-block-end: 1rem;
}

margin-block-start

Spacing before the element on the block axis.

margin-block-end

Spacing after the element on the block axis.

Try It Yourself

How It Works

Use longhand when you need to change only one block side. Use shorthand when both sides share a simple pattern.

Logical vs Physical Margins

LogicalPhysical (horizontal writing)
margin-block-startmargin-top
margin-block-endmargin-bottom
margin-inline-startmargin-left (LTR)
margin-inline-endmargin-right (LTR)
When to choose logical properties

Prefer margin-block when your layout must work across writing modes and directions. Physical margins are fine for simple single-language pages.

♿ Accessibility

  • Preserve reading order — Logical margins respect direction and writing mode, which helps RTL and multilingual users.
  • Keep section spacing consistent — Use block-axis margins for vertical rhythm between headings and paragraphs.
  • Do not hide content with negative margins — Negative block margins can overlap focusable elements.
  • Test zoom and small screens — Large block margins can push content off-screen on narrow viewports.
  • Combine with semantic HTML — Margins adjust spacing; structure still comes from proper elements.

🧠 How margin-block Works

1

You set block-axis spacing

Apply margin-block with one or two values for block-start and block-end.

CSS rule
2

Browser maps logical sides

Block-start and block-end are resolved from writing mode and direction.

Logical layout
3

Outer space is reserved

Transparent margin area is added on the block axis, pushing neighbors apart.

Box model
=

Adaptable vertical rhythm

Spacing stays meaningful when writing mode or text direction changes.

🖥 Browser Compatibility

The margin-block property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. As always, it is advisable to test your website across different browsers to ensure consistent behavior.

Modern browsers · Logical properties

Reliable in current browser versions

margin-block is part of the CSS Logical Properties module. Use it in modern projects; provide physical fallbacks only if you must support very old browsers.

96% Global browser support
Google Chrome 87+ · Desktop & Mobile
Full support
Mozilla Firefox 66+ · Desktop & Mobile
Full support
Apple Safari 14.1+ · macOS & iOS
Full support
Microsoft Edge 87+ · Chromium
Full support
Opera 73+ · Modern
Full support
margin-block property 96% supported

Bottom line: Safe for modern sites. For side-specific control, see margin-block-end.

🎉 Conclusion

The margin-block property is a useful shorthand for setting vertical margins on block-level elements, especially in documents with diverse writing modes and directions.

It simplifies layout management by providing a unified way to handle block margins, adapting to the document’s writing mode. By using this property, you can create more adaptable and responsive layouts.

💡 Best Practices

✅ Do

  • Use margin-block in multilingual and RTL layouts
  • Prefer rem for scalable block-axis spacing
  • Pair with other logical properties for consistent layouts
  • Use one value when block-start and block-end should match
  • Test with different writing modes when building international UIs

❌ Don’t

  • Mix logical and physical margins on the same axis without reason
  • Assume block-start always means top in every layout
  • Use huge fixed margins that break mobile layouts
  • Forget margin collapse between stacked block elements
  • Skip browser testing for older Safari versions

Key Takeaways

Knowledge Unlocked

Five things to remember about margin-block

Use these points when spacing elements on the block axis.

5
Core concepts
0 02

Default 0

No spacing.

Default
2 03

Two values

Start and end.

Syntax
wm 04

Writing mode

Adapts flow.

Logical
LH 05

Longhand

start + end.

Related

❓ Frequently Asked Questions

The margin-block property is a shorthand that sets outer spacing on the block-start and block-end sides of an element. In horizontal writing, that is usually top and bottom.
The default value is 0, meaning no block-axis margin unless you set one explicitly.
margin-top and margin-bottom always target physical top and bottom. margin-block follows the writing mode, so spacing stays correct when text flow or direction changes.
It is shorthand for margin-block-start and margin-block-end.
Use it when you want vertical spacing that adapts to writing mode and direction, especially in multilingual or RTL layouts.

Practice in the Live Editor

Open the HTML editor, try different margin-block values, and see how block-axis spacing changes your layout.

HTML Editor →

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.

5 people found this page helpful