Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

CSS property `left`

`left` sets the physical offset from a positioned box’s left edge to the relevant edge of its containing block.

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

Syntax

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

left sets the physical offset from a positioned box’s left edge to the relevant edge of its containing block.

The example compares an absolutely positioned child x coordinate before and after left:12px.

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

It has no effect on position:static and is physical; direction-aware layouts should prefer inset-inline-start. Over-constrained left/right/width values use conflict-resolution rules.

Examples

<!doctype html><html lang="en"><meta charset="utf-8"><title>CKTIS CSS example</title><body><pre id="result"></pre><script>const g=document.createElement("div"),x=document.createElement("i");document.body.prepend(g);g.append(x);g.style.cssText="position:relative;width:100px;height:40px";x.style.cssText="position:absolute;width:20px;height:10px";const a=g.getBoundingClientRect(),x0=Math.round(x.getBoundingClientRect().left-a.left);x.style.left="12px";const x1=Math.round(x.getBoundingClientRect().left-a.left);document.querySelector("#result").textContent="child-x="+x0+"->"+x1+"; computed="+getComputedStyle(x).left;</script></body></html>

Result

child-x=0->12; computed=12px

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

Sources