Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

CSS property `margin-inline`

`margin-inline` is a shorthand for the inline-start and inline-end margins, mapped by writing mode and text direction.

Version: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review

Syntax

<'margin-top'>{1,2}

margin-inline is a shorthand for the inline-start and inline-end margins, mapped by writing mode and text direction.

With writing-mode: vertical-rl and LTR direction, 8px 14px means physical top and bottom margins. The example measures the 8px top gap and the 14px gap to the next item.

Grammar: <'margin-top'>{1,2}.

One value sets both ends; two values mean inline-start then inline-end. Inline margins do not collapse; auto can instead absorb available space in an appropriate layout.

Examples

<!doctype html><meta charset="utf-8"><div id="box"><i id="first"></i><i id="second"></i></div><pre id="result"></pre><script>
box.style.cssText='display:flex;writing-mode:vertical-rl;direction:ltr;width:60px;height:100px';first.style.cssText='display:block;width:20px;height:20px;margin-inline:8px 14px';second.style.cssText='display:block;width:20px;height:20px';
const p=box.getBoundingClientRect(),a=first.getBoundingClientRect(),b=second.getBoundingClientRect(),s=getComputedStyle(first);result.textContent='top-gap='+Math.round(a.top-p.top)+'; item-gap='+Math.round(b.top-a.bottom)+'; physical='+s.marginTop+' '+s.marginBottom;
</script>

Result

top-gap=8; item-gap=14; physical=8px 14px

The example was executed locally in an isolated, network-free Chrome session; the result comes from the browser CSS API.

Sources