Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

CSS margin-block 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-block property is a logical shorthand that sets the space on an element’s block-start and block-end sides according to the current writing mode. Instead of targeting physical directions like top or bottom, it follows the block axis of the layout so the same rule adapts automatically when content flows vertically or right-to-left; this behavior depends on how the page’s block axis is defined by properties such as writing-mode. Using the logical axis makes styles more robust for internationalization and for UAs that support vertical text.

In layout terms, margin-block affects how much separation an element creates along the block axis and participates in the normal margin behavior of the formatting context (including interactions like margin collapsing between adjacent block-level elements). Because it targets the logical block sides, it’s the logical counterpart to traditional physical margin rules—useful when you want a single rule to work across multiple writing modes rather than maintaining separate top/bottom declarations for every orientation. It is part of the broader set of logical properties that let you express spacing that adapts to flow direction.

For practical authoring, pair margin-block with the inline-axis logical shorthand when you need full two-axis control; for example, combine it with margin-inline to express both block and inline spacing in a writing-mode–agnostic way. If you’re migrating from older CSS, consider how these logical shorthands relate to the classic box properties (for example, margin) and prefer logical properties when building components that must behave consistently across different locales and orientations.

Definition

Initial value
See individual properties
Applies to
same as margin
Inherited
no
Computed value
See individual properties
Animatable
See individual properties
JavaScript syntax
object.style.marginBlock

Interactive Demo

One
Two
Three

Syntax

margin-block: <margin-top> {1,2} 

Values

  • <margin-top> {1,2}Specifies margin-block in px, pt, cm, etc. Negative values are allowed.

Example

<section class="example">
<h2>Margin Block Example</h2>
<p class="boxed">This paragraph uses <code>margin-block</code> to set vertical spacing.</p>
<p class="boxed">Another paragraph to show block-start and block-end margins.</p>

<div class="vertical">
<p class="boxed">In vertical writing-mode, <code>margin-block</code> still affects the block-axis spacing.</p>
</div>
</section>
/* Basic page styles */
.example {
    max-width: 700px;
    margin: 1rem auto;
    padding: 1rem;
    border: 1px solid #e6e9f0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
    color: #111827;
}

/* Example boxes using margin-block */
.boxed {
    background: #f8fafc;
    padding: 0.75rem 1rem;
    margin-block: 1.5rem 0.5rem; /* block-start 1.5rem, block-end 0.5rem */
    border-left: 4px solid #4f46e5;
    border-radius: 6px;
}

/* Vertical example to demonstrate logical axis behavior */
.vertical {
    writing-mode: vertical-rl;
    border-top: 1px dashed #d1d5db;
    padding: 1rem;
    margin-top: 1.5rem;
}

.vertical .boxed {
    margin-block: 2rem 1rem;
}

Browser Support

The following information will show you the current browser support for the CSS margin-block 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!