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.
Fundamentals
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.
Foundation
📝 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:startend;}
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:20px40px;}
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
0
Applies to
All elements except table display types that use separate border model
Inherited
No
Animatable
Yes, as a length
Longhand properties
margin-inline-start, margin-inline-end
Reference
💎 Property Values
Value
Example
Meaning
Length
margin-inline: 20px 40px;
Fixed margin in px, em, rem, etc.
Percentage
margin-inline: 5%;
Margin as a percentage of the containing element width
auto
margin-inline: auto;
The browser calculates a suitable margin
initial
margin-inline: initial;
Sets the property to its default value (0)
inherit
margin-inline: inherit;
Inherits the margin value from the parent element
inline-startinline-end
Default
🎯 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.
Preview
👀 Live Preview
A box with unequal inline-start and inline-end margins inside a dashed container:
margin-inline: 1rem 2rem
Hands-On
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:20px40px;border:1px solid #ccc;padding:10px;}</style><p>This paragraph has 20px inline-start and 40px inline-end margin.</p>
Use longhand when you need to change only one inline side. Use shorthand when both sides share a simple pattern.
Context
Logical vs Physical Margins
Logical
Physical (horizontal LTR)
margin-inline-start
margin-left
margin-inline-end
margin-right
margin-block-start
margin-top
margin-block-end
margin-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.
A11y
♿ 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.
Compatibility
🖥 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 Chrome87+ · Desktop & Mobile
Full support
Mozilla Firefox66+ · Desktop & Mobile
Full support
Apple Safari14.1+ · macOS & iOS
Full support
Microsoft Edge87+ · Chromium
Full support
Opera73+ · Modern
Full support
margin-inline property96% supported
Bottom line: Safe for modern sites. For side-specific control, see margin-inline-end.
Wrap Up
🎉 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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about margin-inline
Use these points when spacing elements on the inline axis.
5
Core concepts
↔01
Inline Axis
Start and end.
Purpose
002
Default 0
No spacing.
Default
203
Two values
Start and end.
Syntax
RTL04
Direction
Adapts flow.
Logical
LH05
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.