CKTIS / CSS
sibling-index(): a one-based position in the DOM
Derive a numeric value from an element’s position among all of its element siblings.
Version: CSS Modules
Syntax
width: calc(sibling-index() * 10px);sibling-index() takes no arguments and returns an integer starting at 1 for the first element child of a parent. Different tag names share the same sequence; text and comments do not take positions. This resembles the numbering used by :nth-child(), but produces a number for a property calculation rather than selecting elements. Subtract 1 when a zero-based offset is needed, for example in a staggered delay.
The index follows DOM order. Flex order, grid placement or a transform can change where an item appears without renumbering it. A hidden element still occupies its position. Consequently, this is not a visible-row number or an nth-of-type index. Reordering actual DOM nodes or inserting an element before the target changes the value; the current syntax has no selector filter.
The example gives three differently named children widths of 10px, 20px and 30px. Moving the third visually to the front with order: -1 leaves all widths unchanged. Prepending a hidden b then makes that same target fourth and its width 40px. The geometry check confirms the visual move separately, showing why appearance and DOM position must not be confused.
Examples
const style=document.createElement('style');style.textContent='#index-stage>*{flex:none;width:calc(sibling-index() * 10px);height:10px}';document.head.append(style);
const parent=document.createElement('div');parent.id='index-stage';parent.style.display='flex';
parent.innerHTML='text<!-- comment --><div></div><span></span><i></i>';document.body.append(parent);
const children=[...parent.children],target=children[2];
const widths=()=>children.map(child=>getComputedStyle(child).width).join(',');
const initial=widths();target.style.order='-1';const reordered=widths();
const first=target.getBoundingClientRect().left<children[0].getBoundingClientRect().left;
const hidden=document.createElement('b');hidden.hidden=true;parent.prepend(hidden);
console.log('initial='+initial+'; reordered='+reordered+'; visually-first='+first+'; after-hidden-prefix='+getComputedStyle(target).width+'; supported='+CSS.supports('width','calc(sibling-index() * 10px)'));Result
initial=10px,20px,30px; reordered=10px,20px,30px; visually-first=true; after-hidden-prefix=40px; supported=true
Executed in Chromium 157.0.8103.51. Treat this CSS Values Level 5 draft feature as progressive enhancement with a fallback and @supports. The example uses ordinary DOM elements, not shadow-tree or pseudo-element resolution.