CSS margin-inline Property

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

What You’ll Learn

The margin-inline property sets outer spacing on the inline axis using logical sides instead of physical left and right margins.

01

Inline Axis

Start and end.

02

Shorthand

1 or 2 values.

03

RTL

Direction aware.

04

Logical

Not left/right.

05

Longhand

start + end.

06

Default 0

No spacing.

Introduction

The margin-inline property in CSS is a shorthand property that sets the margin on the inline-start and inline-end sides of an element.

Unlike the margin-left and margin-right properties, which set margins relative to the physical left and right, margin-inline adjusts margins based on the logical order of content. This makes it especially useful in multilingual and internationalized web design, where text direction can vary between left-to-right (LTR) and right-to-left (RTL) languages.

Definition and Usage

Apply margin-inline when you want horizontal spacing that stays correct when direction changes. Use one value for equal inline-start and inline-end margins, or two values for different spacing on each side.

💡
Beginner Tip

In normal horizontal English pages, margin-inline: 20px 40px behaves like margin-left: 20px and margin-right: 40px. The difference appears when text direction changes to RTL.

📝 Syntax

The syntax for the margin-inline property can be written in several ways, depending on the number of values specified:

syntax.css
element {
  margin-inline: start end;
}
  • If one value is provided, it applies to both margin-inline-start and margin-inline-end.
  • If two values are provided, the first value applies to margin-inline-start and the second to margin-inline-end.

Basic Example

margin-inline.css
p {
  margin-inline: 20px 40px;
}

⚡ Quick Reference

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

💎 Property Values

ValueExampleMeaning
Lengthmargin-inline: 20px 40px;Fixed margin in px, em, rem, etc.
Percentagemargin-inline: 5%;Margin as a percentage of the containing element width
automargin-inline: auto;The browser calculates a suitable margin
initialmargin-inline: initial;Sets the property to its default value (0)
inheritmargin-inline: inherit;Inherits the margin value from the parent element
inline-start inline-end

🎯 Default Value

The default value of margin-inline is 0, meaning no margin is applied to the inline-start and inline-end sides by default. You can override it with one or two values, or with the longhand properties margin-inline-start and margin-inline-end.

👀 Live Preview

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

margin-inline: 1rem 2rem

Examples Gallery

Set different inline-start and inline-end margins, apply a single value, see RTL direction behavior, and compare with longhand properties.

🔢 Inline-Axis Spacing

Start with the reference example — apply different margins on inline-start and inline-end.

Example 1 — Two-Value margin-inline

Apply different margins to the inline-start and inline-end sides of a paragraph element.

margin-inline.html
<style>
  p {
    margin-inline: 20px 40px;
    border: 1px solid #ccc;
    padding: 10px;
  }
</style>

<p>This paragraph has 20px inline-start and 40px inline-end margin.</p>
Try It Yourself

How It Works

In an LTR layout, inline-start is left and inline-end is right. The first value sets start spacing; the second sets end spacing.

Example 2 — Single Value

One value applies equal margin on both inline sides.

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

How It Works

margin-inline: 1.5rem is shorthand for equal spacing on both inline sides.

📈 Direction & Longhand

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

Example 3 — RTL Direction Adaptation

The same margin-inline rule follows the inline axis when direction changes to RTL.

margin-inline-rtl.css
.box {
  margin-inline: 1rem 2rem;
  padding: 0.75rem;
  background: #eff6ff;
}

.rtl {
  direction: rtl;
}

LTR (direction: ltr)

Inline-start is left

RTL (direction: rtl)

Inline-start is right
Try It Yourself

How It Works

Logical inline margins swap sides automatically in RTL. Physical left/right margins would not adapt the same way.

Example 4 — Longhand Equivalent

These two rules produce the same result in horizontal LTR writing:

margin-inline-longhand.css
/* Shorthand */
.panel {
  margin-inline: 1rem 2rem;
}

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

margin-inline-start

Spacing before the element on the inline axis.

margin-inline-end

Spacing after the element on the inline axis.

Try It Yourself

How It Works

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

Logical vs Physical Margins

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

Prefer margin-inline when your layout must work across text directions. Physical margins are fine for simple single-language LTR pages.

♿ Accessibility

  • Preserve reading order — Logical margins respect direction, which helps RTL and multilingual users.
  • Keep horizontal spacing consistent — Use inline-axis margins for gutters and side spacing in content blocks.
  • Do not hide content with negative margins — Negative inline margins can overlap focusable elements.
  • Test zoom and small screens — Large inline margins can push content off-screen on narrow viewports.
  • Combine with semantic HTML — Margins adjust spacing; structure still comes from proper elements.

🧠 How margin-inline Works

1

You set inline-axis spacing

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

CSS rule
2

Browser maps logical sides

Inline-start and inline-end are resolved from writing mode and text direction.

Logical layout
3

Outer space is reserved

Transparent margin area is added on the inline axis on each side you specify.

Box model
=

Direction-aware spacing

Horizontal gutters adapt gracefully to LTR and RTL content.

🖥 Browser Compatibility

The margin-inline property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It is always a good practice to test your website across different browsers to ensure compatibility.

Modern browsers · Logical properties

Reliable in current browser versions

margin-inline 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-inline property 96% supported

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

🎉 Conclusion

The margin-inline property is a versatile tool for managing margins in a way that respects the text direction of different languages.

By using this property, web developers can create layouts that adapt gracefully to both LTR and RTL content. Experiment with different values and see how margin-inline can enhance your web design projects.

💡 Best Practices

✅ Do

  • Use margin-inline in multilingual and RTL layouts
  • Prefer rem for scalable inline-axis spacing
  • Pair with other logical properties for consistent layouts
  • Use one value when inline-start and inline-end should match
  • Test with direction: rtl on international UIs

❌ Don’t

  • Mix logical and physical margins on the same axis without reason
  • Assume inline-start always means left in every layout
  • Use huge fixed margins that break mobile layouts
  • Rely on physical left/right when direction may change
  • Skip browser testing for older Safari versions

Key Takeaways

Knowledge Unlocked

Five things to remember about margin-inline

Use these points when spacing elements on the inline axis.

5
Core concepts
0 02

Default 0

No spacing.

Default
2 03

Two values

Start and end.

Syntax
RTL 04

Direction

Adapts flow.

Logical
LH 05

Longhand

start + end.

Related

❓ Frequently Asked Questions

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

Practice in the Live Editor

Open the HTML editor, try different margin-inline values, and see how inline-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