sibling-index() CSS Function
The sibling-index() function returns the position of an element among its siblings, starting at 1, useful for staggered animations.
Description
The sibling-index() CSS function returns an integer giving the position of the element among its siblings: 1 for the first child of its parent, 2 for the second, and so on. It is one of the tree-counting functions, together with sibling-count(). Because the result is a plain <integer>, it can be used inside calc() and other math functions to make styles depend on an element's position, without adding classes or style attributes in the HTML.
This removes the need for long lists of :nth-child() rules. Common uses include staggering animation delays so items appear one after another, spreading colors across a list by changing the hue for each item, and offsetting or rotating items based on their order. The count includes all element siblings, whatever their type, and ignores text nodes.
/* Items fade in one after another */
.list li {
animation: fade-in 0.4s both;
animation-delay: calc((sibling-index() - 1) * 100ms);
}
/* A different hue for each item */
.tag {
background: hsl(calc(sibling-index() * 40deg) 70% 50%);
}
Tree-counting functions are a recent addition and are not yet available in every browser, so keep a sensible default for browsers that do not support them.
Interactive Demo
- One
- Two
- Three
- Four
- Five
Syntax
sibling-index() = sibling-index()
Values
- (no arguments)The function takes no arguments. It returns an <integer>: the element's 1-based position among its parent's element children.
Example
Browser Support
The following information will show you the current browser support for the CSS sibling-index() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





