Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Container Queries and Logical Properties

The margin-inline property

Reference for the CSS margin-inline shorthand: logical margins along the inline axis, centering with auto, direction awareness, examples and notes.

The margin-inline shorthand sets the outer space at the start and end of the inline axis, the direction in which text runs within a line. In English that means the left (start) and right (end) margins. In Arabic or Hebrew the start is the right side, and in vertical writing modes the inline axis is vertical.

It sets two longhands: margin-inline-start and margin-inline-end. Its best-known use is margin-inline: auto, which centers a block with a set width in any language and writing mode.

CSS
.container { max-inline-size: 60rem; margin-inline: auto; }
.icon { margin-inline-end: 0.5rem; }

Try it

Centering and spacing
Follows text direction

Syntax

CSS
margin-inline: <'margin-left'>{1,2};
  • Initial value: 0
  • Applies to: the same elements as margin
  • Inherited: no
  • Percentages: relative to the inline size of the containing block
  • Animatable: yes (as a length or percentage)
  • Computed value: as specified, with lengths made absolute

Values

Value Description
One value Applied to both the inline-start and inline-end margins.
Two values The first is inline-start, the second inline-end.
<length> A fixed size. Negative values are allowed.
<percentage> A share of the containing block's inline size.
auto Absorbs available space. With auto on both sides, a block box with a definite inline size is centered.

Usage notes

  • Centering needs a size. margin-inline: auto only visibly centers when the box is narrower than its container, for example through inline-size, max-inline-size or width. A block with no width already fills the line.
  • Direction aware. The start side flips with the dir attribute or the CSS direction property, so icons and gutters mirror automatically in right-to-left languages.
  • Writing modes. In a vertical mode the inline axis is vertical, so margin-inline: auto centers the box vertically instead.
  • One side only. Use margin-inline-start or margin-inline-end. In a two-value shorthand, write 0 to keep a side unchanged.
  • Margins can be negative. Negative inline margins widen a box beyond its container, a handy trick for full-bleed images inside a narrow column.

Browser support

Supported in all current browsers.