function

Sibling index() — CSS reference

Returns the one-based index among sibling elements, including the element itself. Unlike a generated counter string, its integer result participates in numeric calculations. Inserting or reordering siblings can change the value.

Formal Syntax & Structure

css syntaxcss
width: calc(sibling-index() * 40px);

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>sibling-index()</title><style>body{margin:16px;font:16px/1.5 system-ui;background:white;color:#172033} .demo{background:#dbeafe;box-sizing:border-box} button,select{font:inherit}#list>div{width:calc(sibling-index()*40px)}</style><body><div id="list"><div id="a" class="demo">A</div><div id="b" class="demo">B</div><div id="c" class="demo">C</div></div></body></html>
CSS Reference