Limited supportUse with care and confirm browser support before shipping it to all users.

Overview

The sibling-count() and sibling-index() CSS functions return integers that are useful to style elements based on their positions among siblings or on the number of siblings, for example as part of a calc() expression. It is useful when you need more deliberate control over presentation or behavior in a focused part of the interface.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
138
138
26.2
138
26.2
Other

The sibling-index() CSS function returns an integer representing the position of the current element in the DOM tree relative to all its sibling elements. The returned value is the index number of the contextual child's position among all the sibling elements within a parent element, with the first child returning 1 and the last child, returning the length…

138
138
26.2
138
26.2
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

CSS
.item {
  width: calc(100% / sibling-count());
  animation-delay: calc(sibling-index() * 0.1s);
}

Live demo

equalwidth (3siblings)

CSS equalwidth (3siblings) demo.

PreviewFullscreen

equalwidth (4siblings)

CSS equalwidth (4siblings) demo.

PreviewFullscreen

delayanime

CSS delayanime demo.

PreviewFullscreen

Use cases

  • Use sibling-count() and sibling-index()

    Use sibling-count() and sibling-index() when the default CSS behavior is not expressive enough for the component or layout you are building.

  • Handle edge cases

    Apply sibling-count() and sibling-index() to solve a specific styling constraint without introducing broader layout or behavior changes.

Cautions

  • Test sibling-count() and sibling-index() in the browsers you support, especially if it changes layout, text handling, or interaction behavior.
  • Plan a fallback or acceptable degradation path when support is still limited.

Accessibility

  • Confirm that using sibling-count() and sibling-index() does not make content harder to perceive, understand, or operate in assistive contexts.

Powered by web-features