CSS margin-inline-start Property

The CSS margin-inline-start property sets the outer margin at the beginning of an element's inline axis, with the physical side determined by its writing mode and text direction.

In a left-to-right horizontal writing mode, margin-inline-start corresponds to margin-left. In right-to-left layouts, it corresponds to margin-right. This logical property allows components to adapt to different writing directions without changing their margin declarations.

margin-inline-start Syntax

The margin-inline-start property accepts a CSS length, percentage, or the auto keyword. CSS-wide keywords are also supported.

Basic Syntax

selector {
  margin-inline-start: 20px;
}

Length Value

div {
  margin-inline-start: 2rem;
}

Percentage Value

div {
  margin-inline-start: 5%;
}

Auto Value

div {
  margin-inline-start: auto;
}

Negative Value

div {
  margin-inline-start: -15px;
}

CSS-Wide Keywords

div {
  margin-inline-start: initial;
}
div {
  margin-inline-start: inherit;
}
div {
  margin-inline-start: unset;
}
div {
  margin-inline-start: revert;
}
div {
  margin-inline-start: revert-layer;
}

The initial value of margin-inline-start is 0.

Property Values

Value Description
<length> Sets the inline-start margin using a length such as px, em, rem, or vw.
<percentage> Sets the margin as a percentage of the containing block's inline size.
auto Allows the browser to calculate the margin according to the formatting context.
initial Resets the property to its initial value of 0.
inherit Inherits the computed value from the parent element.
unset Resets the property to 0 because margins are not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value 0
Inherited No
Applies to Same as the corresponding physical margin properties
Computed value Absolute length, percentage, or auto
Animation type Length, percentage, or calculated combination
Negative values Allowed for lengths and percentages
Logical axis Inline axis
Physical equivalent Depends on writing-mode and direction

How It Works

The inline axis describes the direction in which text and inline content progress. The margin-inline-start property creates outer spacing at the beginning of that axis.

HTML Example

<div class="content-row">
  <span class="content-item">First Item</span>
  <span class="content-item">Second Item</span>
</div>

CSS Example

.content-row {
  display: flex;
}
.content-item {
  margin-inline-start: 20px;
  padding: 10px;
  border: 2px solid #2563eb;
  background-color: #dbeafe;
}

In a left-to-right horizontal layout, each item receives a 20-pixel left margin. In a right-to-left layout, the same declaration creates a 20-pixel right margin.

Remove the First Item's Margin

.content-item:first-child {
  margin-inline-start: 0;
}

This removes unnecessary spacing before the first item while preserving spacing between the remaining items.

Writing Modes and Direction

The physical side controlled by margin-inline-start depends on the element's writing-mode and direction.

Writing Mode Direction Inline-Start Side
horizontal-tb ltr Left
horizontal-tb rtl Right
vertical-rl ltr Top
vertical-rl rtl Bottom
vertical-lr ltr Top
vertical-lr rtl Bottom

Left-to-Right Horizontal Layout

.ltr-box {
  writing-mode: horizontal-tb;
  direction: ltr;
  margin-inline-start: 20px;
}

The margin appears on the left side.

Right-to-Left Horizontal Layout

.rtl-box {
  writing-mode: horizontal-tb;
  direction: rtl;
  margin-inline-start: 20px;
}

The margin appears on the right side.

Vertical Writing Mode

.vertical-box {
  writing-mode: vertical-rl;
  direction: ltr;
  margin-inline-start: 20px;
}

The margin appears on the top side because the inline direction progresses downward.

Important Consideration

Changing the writing mode or direction changes which physical side receives the margin without changing the margin-inline-start declaration.

Physical vs. Logical Margins

Physical margin properties target fixed sides, while logical margins follow the writing mode and direction.

Physical Left Margin

.box {
  margin-left: 20px;
}

Logical Inline-Start Margin

.box {
  margin-inline-start: 20px;
}

These declarations are equivalent in a left-to-right horizontal writing mode.

Comparison

Feature margin-left margin-inline-start
Physical side Always left Depends on writing mode and direction
Horizontal LTR Left Left
Horizontal RTL Left Right
Vertical writing modes Left Top or bottom
Direction-aware No Yes

Important Consideration

Logical margins are especially useful for multilingual interfaces, navigation menus, and components that support both left-to-right and right-to-left text.

Length Values

The margin-inline-start property supports absolute and relative CSS length units.

Pixels

.box {
  margin-inline-start: 24px;
}

Root Font Size

.box {
  margin-inline-start: 2rem;
}

Element Font Size

.box {
  margin-inline-start: 1.5em;
}

Viewport Units

.box {
  margin-inline-start: 3vw;
}

Calculated Value

.box {
  margin-inline-start: calc(1rem + 10px);
}

Important Consideration

Relative units such as rem can help keep spacing proportional as font sizes and viewport dimensions change.

Percentage Values

Percentage inline-start margins are calculated relative to the containing block's inline size, normally its width in horizontal writing modes.

Percentage Example

.box {
  margin-inline-start: 5%;
}

Percentage with a Fixed Container Width

.container {
  width: 600px;
}
.container .box {
  margin-inline-start: 10%;
}

In a horizontal writing mode, the 10% margin equals 60 pixels when the containing block's width is 600 pixels.

Important Consideration

Percentage margins use the containing block's inline size even when the logical margin maps to a top or bottom physical side in a vertical writing mode.

Auto Margins

The auto keyword allows the browser to calculate the inline-start margin according to the layout context.

Basic Example

.box {
  margin-inline-start: auto;
}

Flexbox Example

.flex-container {
  display: flex;
  width: 100%;
}
.flex-item:last-child {
  margin-inline-start: auto;
}

In a horizontal flex row with available free space, the last item's automatic inline-start margin absorbs that space, pushing the item toward the inline-end side.

Centered Block

.centered-box {
  width: 300px;
  max-width: 100%;
  margin-inline-start: auto;
  margin-inline-end: auto;
}

Using automatic margins on both inline sides can center a constrained block in normal block layout.

Important Consideration

An automatic inline-start margin does not always create visible spacing. Its behavior depends on the available free space and formatting context.

Negative Margins

Negative inline-start margins reduce the margin contribution and can move an element toward or beyond its inline-start boundary.

Negative Length

.box {
  margin-inline-start: -20px;
}

Negative Percentage

.box {
  margin-inline-start: -5%;
}

Overlapping Items

.item {
  display: inline-block;
  margin-inline-start: -10px;
  padding: 12px;
  border: 1px solid #2563eb;
}

In a horizontal writing mode, the negative margin reduces the space contributed at the inline-start side and can cause adjacent items to overlap.

Important Consideration

Negative margins can cause unintended overlap or overflow. Test these layouts at different viewport sizes and in both left-to-right and right-to-left directions.

margin-inline Shorthand

The margin-inline shorthand sets both inline-start and inline-end margins.

Individual Properties

.box {
  margin-inline-start: 10px;
  margin-inline-end: 30px;
}

Equivalent Shorthand

.box {
  margin-inline: 10px 30px;
}

The first value sets inline-start, and the second sets inline-end.

Equal Inline Margins

.box {
  margin-inline: 20px;
}

Both inline margins are 20 pixels.

Shorthand Reset Behavior

.box {
  margin-inline-start: 30px;
  margin-inline: 10px;
}

The final inline-start margin is 10 pixels because the later shorthand resets both inline margins.

Override Only Inline-Start

.box {
  margin-inline: 20px;
  margin-inline-start: 40px;
}

The final inline-start margin is 40 pixels, while inline-end remains 20 pixels.

Flexbox and Grid

The margin-inline-start property works with Flexbox and CSS Grid. It can create spacing before individual items or control their alignment.

Flexbox Example

.flex-container {
  display: flex;
  gap: 10px;
}
.flex-item:last-child {
  margin-inline-start: auto;
}

In a horizontal flex row, the last item can be pushed toward the inline-end side when available free space exists.

Grid Example

.grid-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
}
.grid-item {
  margin-inline-start: 20px;
}

Each grid item receives an inline-start margin within its grid area.

Using gap Instead

.grid-container {
  display: grid;
  gap: 20px;
}

The gap property is generally preferable for consistent spacing between flex or grid items because it does not add margins around the outside edges.

Important Consideration

Use margin-inline-start when a specific item needs additional spacing before it. Use gap for uniform spacing between items.

Responsive Spacing

Inline-start margins can be adjusted for different viewport sizes using relative units, media queries, and CSS functions.

Media Query Example

.content-item {
  margin-inline-start: 30px;
}
@media (max-width: 768px) {
  .content-item {
    margin-inline-start: 10px;
  }
}

Using rem Units

.content-item {
  margin-inline-start: 1.5rem;
}

Fluid Spacing with clamp()

.content-item {
  margin-inline-start: clamp(0.5rem, 2vw, 2rem);
}

Important Consideration

Responsive inline spacing should account for available width and text direction. Large fixed margins can cause overflow on narrow screens.

margin-inline-start Example

This example demonstrates how different inline-start margin values change the spacing before an item in a horizontal flex layout.

HTML Example

<div class="margin-inline-start-demo">
  <div class="demo-section">
    <h3>No Inline-Start Margin</h3>
    <div class="margin-area">
      <div class="demo-box first-box">First</div>
      <div class="demo-box no-margin">Second</div>
    </div>
  </div>
  <div class="demo-section">
    <h3>20px Inline-Start Margin</h3>
    <div class="margin-area">
      <div class="demo-box first-box">First</div>
      <div class="demo-box medium-margin">Second</div>
    </div>
  </div>
  <div class="demo-section">
    <h3>40px Inline-Start Margin</h3>
    <div class="margin-area">
      <div class="demo-box first-box">First</div>
      <div class="demo-box large-margin">Second</div>
    </div>
  </div>
</div>

CSS Example

.margin-inline-start-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}
.margin-inline-start-demo .demo-section {
  padding: 15px;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
}
.margin-inline-start-demo h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}
.margin-inline-start-demo .margin-area {
  display: flex;
  direction: ltr;
  padding: 12px;
  background-color: #e2e8f0;
}
.margin-inline-start-demo .demo-box {
  flex: 0 0 auto;
  padding: 12px;
  border: 2px solid #2563eb;
  background-color: #bfdbfe;
  color: #1e3a8a;
  text-align: center;
  font-size: 0.875rem;
}
.margin-inline-start-demo .first-box {
  margin: 0;
  border-color: #64748b;
  background-color: #f1f5f9;
  color: #334155;
}
.margin-inline-start-demo .no-margin {
  margin-inline-start: 0;
}
.margin-inline-start-demo .medium-margin {
  margin-inline-start: 20px;
}
.margin-inline-start-demo .large-margin {
  margin-inline-start: 40px;
}
Browser Result

No Inline-Start Margin

First
Second

20px Inline-Start Margin

First
Second

40px Inline-Start Margin

First
Second

As the inline-start margin increases, the space before the second item increases. In this left-to-right layout, the margin appears on the left side of the second item.

Change the Margin to 30px

.margin-inline-start-demo .medium-margin {
  margin-inline-start: 30px;
}

Use a Relative Unit

.margin-inline-start-demo .large-margin {
  margin-inline-start: 2rem;
}

Remove the Margin

.margin-inline-start-demo .large-margin {
  margin-inline-start: 0;
}

Switch to Right-to-Left Direction

.margin-inline-start-demo .margin-area {
  direction: rtl;
}

The inline-start margin now appears on the right side of the second item.

Common Mistakes

Assuming Inline-Start Always Means Left

In right-to-left horizontal layouts, inline-start corresponds to the right side.

Ignoring Vertical Writing Modes

In vertical writing modes, inline-start corresponds to the top or bottom side.

Confusing Inline-Start with Block-Start

margin-inline-start follows the inline axis, while margin-block-start follows the block axis.

Expecting Percentage Values to Use the Physical Side's Dimension

Percentages are calculated from the containing block's inline size.

Expecting Auto to Always Create Space

Automatic margins depend on the formatting context and available free space.

Using Negative Margins Without Testing

Negative margins can cause overlap or overflow.

Overwriting the Value with a Shorthand

.box {
  margin-inline-start: 30px;
  margin-inline: 10px;
}

The final inline-start margin is 10 pixels.

Mixing Physical and Logical Margins

In left-to-right horizontal layouts, margin-left and margin-inline-start target the same side. The CSS cascade determines which declaration wins.

Using Margins Instead of gap for Every Layout

Use gap when consistent spacing between flex or grid items is needed.

Important Considerations

Keep the following points in mind when using margin-inline-start:

  • The property controls the margin at the beginning of the inline axis.
  • It is a logical margin property.
  • The initial value is 0.
  • The property is not inherited.
  • The physical side depends on writing mode and direction.
  • In horizontal LTR layouts, inline-start is the left side.
  • In horizontal RTL layouts, inline-start is the right side.
  • In vertical LTR layouts, inline-start is the top side.
  • In vertical RTL layouts, inline-start is the bottom side.
  • CSS length values are supported.
  • Percentage values are based on the containing block's inline size.
  • The auto keyword is supported.
  • Negative lengths and percentages are allowed.
  • Negative margins can cause overlap or overflow.
  • Margins are outside the element's border.
  • Margins do not extend the element's background.
  • The property can be set using the margin-inline shorthand.
  • The margin shorthand can also affect the corresponding physical side.
  • Physical and logical margin declarations can conflict.
  • The CSS cascade determines which conflicting declaration wins.
  • The property works with Flexbox and CSS Grid.
  • Automatic margins can absorb free space in flex layouts.
  • The gap property is useful for consistent spacing between layout items.
  • Relative units can provide scalable spacing.
  • Media queries can adjust margins for smaller screens.
  • Logical margins are useful for multilingual and writing-mode-aware layouts.

Browser Support

The CSS margin-inline-start property is widely supported across modern browsers, including Chrome, Edge, Firefox, Safari, and Opera.

It is part of CSS Logical Properties and Values. Older browsers may require physical margin fallbacks, such as margin-left for left-to-right horizontal layouts.

For current compatibility information, visit Can I Use? and search for margin-inline-start.

Specifications

The margin-inline-start property is defined in the CSS Logical Properties and Values Module Level 1 specification.

CSS Logical Properties and Values Module Level 1: Margin Properties

The specification defines how logical margin properties map to physical sides according to writing modes and direction.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: margin-inline-start