# sibling-index()

> The `sibling-index()` CSS function returns the position of an element among its siblings.

## How do I stagger animations by element index in CSS?

The function that returns the index of an element among its siblings, starting from '1'. Used inside `calc()` to create staggered animation delays or gradual changes of colors without setting custom properties for every element.

- Topic: Global Functions
- Type: function
- Browser support: Chrome 138+, Chrome Android 138+, Edge 138+, Firefox 154+, Firefox Android 154+, Safari 26.2+, Safari iOS 26.2+

## Example

Wrong:

```css
li:nth-child(1) { animation-delay: 0ms; }
li:nth-child(2) { animation-delay: 100ms; }
li:nth-child(3) { animation-delay: 200ms; }
```

Right:

```css
li {
  animation-delay: calc((sibling-index() - 1) * 100ms);
}
```

One rule replaces a list of `:nth-child` rules, and subtracting 1 starts the first item with no delay.

## Common mistakes

- Expecting the index to count only one element type; it counts all element siblings.

## Key points

- Staggered delays use `calc(sibling-index() * 100ms)` instead of many `:nth-child` rules or inline indexes.
- Math accounts for the index starting at 1, not 0.
- A fallback value is declared first where the function is unsupported.

## Interview questions

### Does sibling-index() start at 0 or 1?

It starts at 1 for the first child. Subtract 1 inside `calc()` when the first item should get a zero value.

### Can I use sibling-index() in a selector?

No. It is a value function used in declarations; use `:nth-child()` to select elements by position.

## Related cards

- [sibling-count()](https://wonderium.dev/css/sibling-count.md)
- [:nth-child(n)](https://wonderium.dev/css/nth-child.md)
- [animation-delay](https://wonderium.dev/css/animation-delay.md)
- [calc()](https://wonderium.dev/css/calc.md)
- [transition-delay](https://wonderium.dev/css/transition-delay.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/sibling-index
- Last updated: 2026-11-25
