<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/css-can-count-now--58t6cpwg3" -->

---
title: CSS can count now! | daily.dev
description: CSS now supports sibling-index() and sibling-count() functions, which let you access an element's position among its siblings and the total sibling count...
canonical: https://daily.dev/posts/css-can-count-now--58t6cpwg3
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: CSS can count now! | daily.dev
og:description: CSS now supports sibling-index() and sibling-count() functions, which let you access an element's position among its siblings and the total sibling count...
og:url: https://daily.dev/posts/css-can-count-now--58t6cpwg3
og:image: https://api.daily.dev/og/posts/58t6CpWg3.png
og:image:alt: CSS can count now!
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# CSS can count now!

**[Kevin Powell](https://daily.dev/sources/kevinpowell)** · 6 min read · 44 upvotes · 7 comments

## Summary

CSS now supports sibling-index() and sibling-count() functions, which let you access an element's position among its siblings and the total sibling count directly in CSS, without JavaScript loops or manual nth-child rules. Firefox recently shipped support, meaning it now works across all major browser engines. The demo walks through using sibling-index() to create staggered slide-in animations for a menu, rotating colors across avatars using hue variables, and solving z-index stacking problems for overlapping avatars, including a hover effect that brings an avatar to the front using sibling-count(). Bonus tips cover using CSS custom properties for timing values and cubic-bezier easing functions for smoother animations.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=6-cg8Z74MPI>

## Questions this post answers

### What does the CSS sibling-index() function do and which browsers support it?

The CSS sibling-index() function returns the numeric position of an element among its siblings, starting at one for the first child. It replaces manual nth-child selectors, HTML-based custom property counters, or JavaScript loops previously used for staggered animations, color cycling, or z-index layering. Firefox recently shipped support, meaning it is now implemented across all major browser engines.

_Track new CSS capabilities like sibling-index on daily.dev as browser support lands._

### How can I use CSS to set z-index on overlapping avatar images without manually assigning a z-index to each one?

Use sibling-count() minus sibling-index() as the z-index value so each element's stacking order is calculated automatically instead of hardcoded. For a five-item list, the first avatar gets z-index 4 (5 minus 1), the second gets 3, and so on, keeping the leftmost avatar on top regardless of how many items are added or removed.

_Developers wrangling z-index stacks can find CSS techniques like this through daily.dev._

### How do I create a staggered CSS animation delay for list items without writing separate nth-child rules for each one?

Multiply the sibling-index() value by a base delay variable, for example transition-delay calculated as sibling-index() times a duration, so each sibling gets a progressively longer delay automatically. This avoids writing individual nth-child(1), nth-child(2), etc. rules or manually setting custom properties in the HTML for each element.

_Anyone building stagger animations can keep up with CSS tricks like this via daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@mavros\_lykos** · 5 upvotes

> ![GIF](https://static.klipy.com/ii/d7aec6f6f171607374b2065c836f92f4/37/c2/7YUD14pp.gif)
>
> wow.. really? have to try that out too

**@hexapaws** · 2 upvotes

> Does that make it a programming language? Because it finally gets _some _form of logic

**@azuzard** · 1 upvotes

> CSS virus coming!

**@bestcodes** · 1 upvotes

> ![GIF](https://static.klipy.com/ii/feea28532d9709f5128558f418c779d0/10/36/4rZGmVf9.gif)

**@mheob** · 0 upvotes

> Cool.
>
> ![GIF](https://static.klipy.com/ii/935d7ab9d8c6202580a668421940ec81/a5/4d/HjZCeR4P.gif)

## Similar posts on daily.dev

- [CSS sibling-index\(\) and sibling-count\(\): Native List Staggering Without JavaScript](https://daily.dev/posts/css-sibling-index-and-sibling-count-native-list-staggering-without-javascript-bsxh6wlwk) · SitePoint · 61 upvotes · 2 comments
- [How to create awesome staggered animations in CSS](https://daily.dev/posts/how-to-create-awesome-staggered-animations-in-css-k09m57ftt) · LogRocket · 52 upvotes · 1 comments
- [Advanced Tree Counting: Mathematical Layouts With sibling-index\(\) And sibling-count\(\) — Smashing Magazine](https://daily.dev/posts/advanced-tree-counting-mathematical-layouts-with-sibling-index-and-sibling-count-smashing-mag-50edoejtv) · Smashing Magazine · 13 upvotes · 1 comments
- [Counting Elements in CSS: Using Sibling-Count and Hacks](https://daily.dev/posts/counting-elements-in-css-using-sibling-count-and-hacks-fyrhrhsyv) · Frontend Masters · 2 upvotes · 0 comments

---

Tags: [#css](https://daily.dev/tags/css)

[View this post on daily.dev](https://daily.dev/posts/css-can-count-now--58t6cpwg3)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"CSS can count now!","url":"https://daily.dev/posts/css-can-count-now--58t6cpwg3","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/css-can-count-now--58t6cpwg3"},"datePublished":"2026-09-09T13:16:50.380Z","dateModified":"2026-09-13T19:23:23.509Z","description":"CSS now supports sibling-index() and sibling-count() functions, which let you access an element's position among its siblings and the total sibling count...","image":"https://i.ytimg.com/vi/6-cg8Z74MPI/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/6-cg8Z74MPI/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Kevin Powell","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Kevin Powell","logo":"https://media.daily.dev/image/upload/s--XK5Rf0kM--/f_auto/v1717745137/logos/kevinpowell","url":"https://daily.dev/sources/kevinpowell"},"commentCount":7,"discussionUrl":"https://daily.dev/posts/css-can-count-now--58t6cpwg3","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":44},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":7}],"keywords":"css","timeRequired":"PT6M","video":{"@type":"VideoObject","name":"CSS can count now!","description":"CSS now supports sibling-index() and sibling-count() functions, which let you access an element's position among its siblings and the total sibling count...","thumbnailUrl":"https://i.ytimg.com/vi/6-cg8Z74MPI/sddefault.jpg","uploadDate":"2026-09-09T13:16:50.380Z","duration":"PT6M","url":"https://api.daily.dev/r/58t6CpWg3","embedUrl":"https://www.youtube.com/embed/6-cg8Z74MPI"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Kevin Powell","item":"https://daily.dev/sources/kevinpowell"},{"@type":"ListItem","position":3,"name":"CSS can count now!"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/css-can-count-now--58t6cpwg3","comment":[{"@type":"Comment","text":"wow… really? have to try that out too","datePublished":"2026-09-09T13:56:24.043Z","url":"https://daily.dev/posts/58t6CpWg3#c-IuSUJS7aN","author":{"@type":"Person","name":"Charaka Hashan","url":"https://daily.dev/mavros_lykos","image":"https://media.daily.dev/image/upload/s--UhlNgzLT--/f_auto/v1786970273/avatars/avatar_rP15vFIdEPNpDSYMOi2AR?_a=BAMAMicg0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":5}},{"@type":"Comment","text":"Does that make it a programming language? Because it finally gets _some _form of logic","datePublished":"2026-09-10T07:09:25.585Z","url":"https://daily.dev/posts/58t6CpWg3#c-d9jo1cp9m","author":{"@type":"Person","name":"HexaPaws","url":"https://daily.dev/hexapaws","image":"https://media.daily.dev/image/upload/s--tvr4YO6b--/f_auto/v1784860169/avatars/avatar_H0URpju3ND0pkrjj1i1mE?_a=BAMAMicg0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"CSS virus coming!","datePublished":"2026-09-13T12:46:58.125Z","url":"https://daily.dev/posts/58t6CpWg3#c-Tiupvcxxb","author":{"@type":"Person","name":"Sema toghem","url":"https://daily.dev/azuzard","image":"https://avatars.githubusercontent.com/u/11573007?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"","datePublished":"2026-09-13T13:39:33.418Z","url":"https://daily.dev/posts/58t6CpWg3#c-GsD92ZI8S","author":{"@type":"Person","name":"BestCodes","url":"https://daily.dev/bestcodes","image":"https://avatars.githubusercontent.com/u/106822363?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Cool.","datePublished":"2026-09-10T16:22:50.930Z","url":"https://daily.dev/posts/58t6CpWg3#c-jsdFvH5fr","author":{"@type":"Person","name":"Alex Böhm","url":"https://daily.dev/mheob","image":"https://avatars3.githubusercontent.com/u/3983539?v=4"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/css-can-count-now--58t6cpwg3#faq","mainEntity":[{"@type":"Question","name":"What does the CSS sibling-index() function do and which browsers support it?","acceptedAnswer":{"@type":"Answer","text":"The CSS sibling-index() function returns the numeric position of an element among its siblings, starting at one for the first child. It replaces manual nth-child selectors, HTML-based custom property counters, or JavaScript loops previously used for staggered animations, color cycling, or z-index layering. Firefox recently shipped support, meaning it is now implemented across all major browser engines. Track new CSS capabilities like sibling-index on daily.dev as browser support lands."}},{"@type":"Question","name":"How can I use CSS to set z-index on overlapping avatar images without manually assigning a z-index to each one?","acceptedAnswer":{"@type":"Answer","text":"Use sibling-count() minus sibling-index() as the z-index value so each element's stacking order is calculated automatically instead of hardcoded. For a five-item list, the first avatar gets z-index 4 (5 minus 1), the second gets 3, and so on, keeping the leftmost avatar on top regardless of how many items are added or removed. Developers wrangling z-index stacks can find CSS techniques like this through daily.dev."}},{"@type":"Question","name":"How do I create a staggered CSS animation delay for list items without writing separate nth-child rules for each one?","acceptedAnswer":{"@type":"Answer","text":"Multiply the sibling-index() value by a base delay variable, for example transition-delay calculated as sibling-index() times a duration, so each sibling gets a progressively longer delay automatically. This avoids writing individual nth-child(1), nth-child(2), etc. rules or manually setting custom properties in the HTML for each element. Anyone building stagger animations can keep up with CSS tricks like this via daily.dev."}}]}
```

