Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

CSS property `margin-left`

`margin-left` sets the physical left margin regardless of text direction or writing mode.

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

Syntax

<length-percentage> | auto | <anchor-size()>

margin-left sets the physical left margin regardless of text direction or writing mode.

Two 200px flex rows demonstrate 10%: in LTR it creates 20px before the first item; in RTL the same 20px lies between the first and second items because the left side becomes logical inline-end. -6px pulls an item beyond the left edge.

Grammar: <length-percentage> | auto | <anchor-size()>.

A percentage uses the containing block’s inline size; negative values and auto are allowed. Collapsing follows the logical block axis: in horizontal writing the left side is an inline side and does not collapse, but in vertical writing it can be block-start or block-end and can collapse where normal-flow rules permit; flex and grid item margins do not participate.

Examples

<!doctype html><meta charset="utf-8"><div id="ltr"><i></i><i></i></div><div id="rtl"><i></i><i></i></div><div id="neg"><i></i><i></i></div><pre id="result"></pre><script>
const setup=(box,dir,value)=>{box.style.cssText='display:flex;direction:'+dir+';width:200px;height:30px';for(const item of box.children)item.style.cssText='display:block;width:20px;height:20px';box.firstElementChild.style.marginLeft=value};setup(ltr,'ltr','10%');setup(rtl,'rtl','10%');setup(neg,'ltr','-6px');const lp=ltr.getBoundingClientRect(),la=ltr.firstElementChild.getBoundingClientRect(),[ra,rb]=[...rtl.children].map(x=>x.getBoundingClientRect()),np=neg.getBoundingClientRect(),na=neg.firstElementChild.getBoundingClientRect(),s=getComputedStyle(rtl.firstElementChild);result.textContent='ltr-left-lead='+Math.round(la.left-lp.left)+'; rtl-item-gap='+Math.round(ra.left-rb.right)+'; physical='+s.marginLeft+'; logical-end='+s.marginInlineEnd+'; negative-lead='+Math.round(na.left-np.left);
</script>

Result

ltr-left-lead=20; rtl-item-gap=20; physical=20px; logical-end=20px; negative-lead=-6

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

Sources