CKTIS / CSS
CSS property `position-anchor`
`position-anchor` selects the default anchor element of an absolutely positioned box; implicit references in `anchor()`, as well as `position-area` and `position-try`, use that default.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
normal | none | auto | <anchor-name> | match-parentposition-anchor selects the default anchor element of an absolutely positioned box; implicit references in anchor(), as well as position-area and position-try, use that default.
The example names two anchors --first and --second; identical labels that differ only in their default anchor land below the corresponding boxes, while the variant using none takes the functions’ fallback lengths.
Grammar: normal | none | auto | <anchor-name> | match-parent.
normal behaves as none when no position area is set, and otherwise as auto; none removes the default anchor, auto selects an implicit anchor, and match-parent attempts to reuse the parent’s anchor. A named anchor must be in scope, acceptable, and laid out earlier; the property is a reset-only component of the position shorthand.
Examples
<!doctype html><meta charset="utf-8"><style>html,body{margin:0}.stage{position:relative;width:300px;height:180px}.anchor{position:absolute}.tip{position:absolute;width:20px;height:10px;left:anchor(center);top:anchor(bottom);translate:-50% 0}#first{left:40px;top:30px;width:60px;height:20px;anchor-name:--first}#second{left:180px;top:100px;width:40px;height:30px;anchor-name:--second}#tip1{position-anchor:--first}#tip2{position-anchor:--second}#fallback{position:absolute;position-anchor:none;left:anchor(center,7px);top:anchor(bottom,9px);width:5px;height:5px}</style><div class="stage"><i id="first" class="anchor"></i><i id="second" class="anchor"></i><b id="tip1" class="tip"></b><b id="tip2" class="tip"></b><b id="fallback"></b></div><pre id="result"></pre><script>const point=e=>{const r=e.getBoundingClientRect();return[Math.round(r.left),Math.round(r.top)]},a=point(tip1),b=point(tip2),f=point(fallback),x=getComputedStyle(tip1).positionAnchor,y=getComputedStyle(tip2).positionAnchor,n=getComputedStyle(fallback).positionAnchor;if(a.join(',')!=='60,50'||b.join(',')!=='190,130'||f.join(',')!=='7,9'||x!=='--first'||y!=='--second'||n!=='none')throw new Error('position-anchor mismatch '+[a,b,f,x,y,n]);result.textContent='tips='+a.join(',')+'/'+b.join(',')+'; fallback='+f.join(',')+'; computed='+x+'/'+y+'/'+n;</script>Result
tips=60,50/190,130; fallback=7,9; computed=--first/--second/none
The example names two anchors `--first` and `--second`; identical labels that differ only in their default anchor land below the corresponding boxes, while the variant using `none` takes the functions’ fallback lengths.