CSS margin-inline Property

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

Definition and Usage

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

In horizontal left-to-right layout that maps to left and right. With direction: rtl or a vertical writing-mode, the physical sides update automatically. The property is not inherited.

Baseline · Widely available.

Not deprecated. Broad support since about 2021. Prefer it over margin-left / margin-right when direction can change.

CSS Syntax

syntax.css
margin-inline: <start> <end>? | auto | inherit;

One value sets both sides. Two values set start then end: margin-inline: 1rem 2rem;.

Property Values

ValueDescriptionTry it
One lengthSame margin on start and end (e.g. 1rem)Try it
Two lengthsStart then end (e.g. 8px 24px)Try it
autoUseful for centering with a set width: margin-inline: autoTry it
<percentage>Relative to the containing block’s inline sizeTry it
With direction: rtlStart/end flip to physical right/leftTry it
0 / inheritReset both sides, or inherit from the parentTry it

How to Use margin-inline

Use it whenever side spacing should follow text direction.

  1. Choose the element that needs inline-axis outer space.
  2. Set one value for equal sides, or two for start and end.
  3. Use margin-inline: auto with a width to center a block.
  4. Prefer this over physical margin-left / margin-right for RTL-ready UI.
PieceRequired?Role
1 or 2 valuesYesSets start (and end) inline margins
Writing mode / directionAffects mappingControls which physical sides get the margins
InheritedNoSet on each element that needs it
Width + autoFor centeringmargin-inline: auto centers a sized block

Live Preview

Change margin-inline and watch the yellow box inset from the container sides.

For auto, the box uses a fixed width so centering is visible.

Container
Inline margins

margin-inline: 1rem

CSS Examples

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

Example 1 — Equal Inline Margins

Inset both inline sides with one value.

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

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

How It Works

  1. One value. Start and end both get 1rem.
  2. Inline axis. In LTR horizontal mode that is left and right.
  3. Outside the border. Space is margin, not padding.
  4. RTL-ready. Change direction and the logical sides still make sense.

Example 2 — Different Start and End

Set start and end separately.

CSS
<style>
  .box {
    margin-inline: 8px 24px;
  }
</style>

<div class="box">Start 8 / End 24</div>
Try It Yourself

How It Works

  1. First value → start. 8px on inline-start.
  2. Second value → end. 24px on inline-end.
  3. In LTR, that is left 8px and right 24px.
  4. In RTL, start is on the right — the larger gap moves with direction.

Example 3 — Center with Auto

Center a fixed-width block on the inline axis.

CSS
<style>
  .box {
    width: 8rem;
    margin-inline: auto;
  }
</style>

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

How It Works

  1. Give the box a width less than the container.
  2. Set margin-inline: auto. Free space splits on both inline sides.
  3. Modern centering. Same idea as classic margin-left/right: auto.
  4. Still logical. Works with direction changes without rewriting left/right.

Edge Cases & Pitfalls

If sides look swapped or centering fails, check these first.

logical

Not the same as left/right forever

Mapping depends on writing-mode and direction. In vertical modes, inline margins can land on top/bottom.

order

Two values are start, then end

margin-inline: 8px 24px is not “left then right” in every language — it is inline-start then inline-end.

auto

auto needs leftover space

Centering with margin-inline: auto needs a width (or max-width) smaller than the container and a block that can take auto margins.

vs

margin-inline vs padding-inline

Margin is outside the border. Use padding-inline for inner side space that keeps the background.

shorthand

Overrides both longhands

Setting margin-inline resets start and end together. Set a longhand afterward if only one side should differ.

Browser Support

margin-inline is a browser CSS property for logical margins. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

margin-inline

Supported in all modern browsers (broad support from about 2021). Prefer it for direction-aware side margins.

96% Modern browser 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 15+
Full support
Internet Explorer No support
No support
margin-inline Widely supported

Bottom line: Safe for modern sites. Fall back to margin-left/right only if you must support very old browsers. It is not a runtime API.

Key Takeaways

  • Shorthand for inline-start and inline-end margins.
  • Follows direction and writing mode — better than physical left/right for i18n.
  • One or two values: equal sides, or start then end.
  • auto centers a sized block on the inline axis.

One line: use margin-inline for side margins that stay correct when text direction changes.

Frequently Asked Questions

It is a shorthand for margin-inline-start and margin-inline-end. It sets outer spacing on the inline axis, which maps to left/right in horizontal LTR and flips with direction or writing mode.
Both longhands default to 0, so there is no inline-axis margin until you set one.
margin-left and margin-right always target physical sides. margin-inline follows writing mode and direction, so spacing stays correct in RTL and vertical layouts.
Yes. One value sets both sides. Two values set start then end, for example margin-inline: 1rem 2rem;
No. Set it on each element that needs inline-axis margins.
It is Baseline Widely available (broad support since about 2021). It is a browser CSS property, not a Node.js feature.

Next: margin-inline-end

Set only the logical inline-end margin.

margin-inline-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