sibling-count() CSS function

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The sibling-count() CSS function returns an integer representing the total number of sibling DOM elements (direct children of the parent) of the element on which it is used, including itself.

Note: The counter() function provides a similar result but it returns a <string> (which is more suitable for generated content, while sibling-count() returns an <integer> (which can be used for calculations).

Syntax

css
sibling-count()

Parameters

The sibling-count() function doesn't accept parameters.

Return value

An integer; the total number of sibling DOM elements including the element itself.

Examples

Dynamic column count

This example demonstrates setting the width of each item in a list based on the number of items, enabling placing each child in its own column.

HTML

We include a <ul> container and several <li> elements children.

html
<ul>
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
  <li>Four</li>
  <li>Five</li>
</ul>

CSS

We divide the width of each list item by the number of direct children the list contains. We also set every odd element to have a background-color to better demonstrate the resulting effect.

css
ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
  text-align: center;
  display: flex;
}

li {
  width: calc(100% / sibling-count());
}

li:nth-of-type(odd) {
  background-color: rgb(0 0 0 / 0.05);
}

Results

Specifications

Specification
CSS Values and Units Module Level 5
# funcdef-sibling-count

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
sibling-count()
Chrome – Full support
Chrome 138 (Release date: 2025-06-24)
footnote Full support
Edge – Full support
Edge 138 (Release date: 2025-06-26)
footnote Full support
Firefox – No support
Firefox
footnote
footnote See bug 1953973
Opera – Full support
Opera 122 (Release date: 2025-09-11)
footnote Full support
Safari – Full support
Safari 26.2 (Release date: 2025-12-12)
footnote Full support
Chrome Android – Full support
Chrome Android 138 (Release date: 2025-06-24)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1953973
Opera Android – Full support
Opera Android 91 (Release date: 2025-08-19)
footnote Full support
Safari on iOS – Full support
Safari on iOS 26.2 (Release date: 2025-12-12)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 138 (Release date: 2025-06-24)
footnote Full support
WebView on iOS – Full support
WebView on iOS 26.2 (Release date: 2025-12-12)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also