# sibling-count()

> The `sibling-count()` CSS function returns the total number of sibling elements including the element itself.

## How do I get the number of siblings in CSS?

The function that returns the number of children of the element's parent. Allows distributing sizes, angles or delays evenly depending on the number of items without JS.

- 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:first-child:nth-last-child(4),
li:first-child:nth-last-child(4) ~ li {
  width: 25%;
}
```

Right:

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

One rule adapts to any number of items instead of a selector chain for each possible count.

## Common mistakes

- Siblings hidden with `display: none` are still counted.

## Key points

- Counts come from `sibling-count()` instead of `:nth-last-child` chains or a custom property set by JavaScript.
- The result is multiplied by a unit inside `calc()`, like `calc(100% / sibling-count())`.
- A fallback value is declared first where the function is unsupported.

## Interview questions

### Does sibling-count() include the element itself?

Yes. It counts all element children of the parent, including the element it is used on.

### Does sibling-count() count text nodes?

No. It counts only element siblings, not text or comment nodes.

## Related cards

- [sibling-index()](https://wonderium.dev/css/sibling-index.md)
- [:nth-child(n)](https://wonderium.dev/css/nth-child.md)
- [:nth-last-child(n)](https://wonderium.dev/css/nth-last-child.md)
- [calc()](https://wonderium.dev/css/calc.md)
- [:has()](https://wonderium.dev/css/has.md)

---

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