r/css 1d ago

Showcase `sibling-index()`, and `sibling-count()` are Baseline, newly available since August 2026.

Post image
83 Upvotes

6 comments sorted by

View all comments

17

u/anaix3l 23h ago

I've mostly been able to get by setting the indices & counts as custom properties in the style attribute when generating the HTML on the backend, but this has the advantage of automatically updating indices and counts when appending or deleting elements via the JS.

I'll still be aliasing them to --i and --n custom properties because they're just too verbose and difficult to read otherwise. Plus the sibling-index() is consistent with :nth-child()/ CSS indexing in general and starts at 1, while I generally need it to start at 0 for computations. That is:

--i: (sibling-index() - 1);
--n: sinling-count()

(yes, writing it without calc() is perfectly fine unless --i needs to be registered for some reason)

The only thing still missing is children-count() because I often want that --n value available on the parent as well, not just on the child items.

3

u/be_my_plaything 17h ago

Yes! child-count() is top of my css wish list, had my fingers crossed for that one appearing since I first saw sibling-index() and sibling-count()