Favorites

sibling-index() CSS Function

sibling-index()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The sibling-index() function returns the position of an element among its siblings, starting at 1, useful for staggered animations.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

Description

The sibling-index() CSS function returns an integer giving the position of the element among its siblings: 1 for the first child of its parent, 2 for the second, and so on. It is one of the tree-counting functions, together with sibling-count(). Because the result is a plain <integer>, it can be used inside calc() and other math functions to make styles depend on an element's position, without adding classes or style attributes in the HTML.

This removes the need for long lists of :nth-child() rules. Common uses include staggering animation delays so items appear one after another, spreading colors across a list by changing the hue for each item, and offsetting or rotating items based on their order. The count includes all element siblings, whatever their type, and ignores text nodes.

/* Items fade in one after another */
.list li {
  animation: fade-in 0.4s both;
  animation-delay: calc((sibling-index() - 1) * 100ms);
}

/* A different hue for each item */
.tag {
  background: hsl(calc(sibling-index() * 40deg) 70% 50%);
}

Tree-counting functions are a recent addition and are not yet available in every browser, so keep a sensible default for browsers that do not support them.

Interactive Demo

  • One
  • Two
  • Three
  • Four
  • Five
Demo Code
HTML Code
<ul class="demo-element">
	<li>One</li>
	<li>Two</li>
	<li>Three</li>
	<li>Four</li>
	<li>Five</li>
</ul>
CSS Code
.demo-element {
	width: 300px;
	margin: 0;
	padding: 0;
}
.demo-element li {
	margin-bottom: 4px;
	padding: 6px 10px;
	background: #4361ee;
	color: #fff;
	font-size: 14px;
	list-style: none;
	width: calc(sibling-index() * 50px);
}

Syntax

sibling-index() = sibling-index()

Values

  • (no arguments)The function takes no arguments. It returns an <integer>: the element's 1-based position among its parent's element children.

Example

<div class="wrap">
<h1>CSS sibling-index() examples</h1>
<div class="card"><ul class="list">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
<div class="label">hsl(calc(sibling-index() * 36deg) 70% 48%) and animation-delay: calc(sibling-index() * 120ms)</div></div>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* sibling-index() examples */
.list {
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 0;
margin: 0;
list-style: none;
}

.list li {
width: 64px;
height: 64px;
border-radius: 12px;
display: grid;
place-items: center;
color: #fff;
font-weight: 700;
background: #2563eb; /* fallback */
background: hsl(calc(sibling-index() * 36deg) 70% 48%);
animation: pop 0.5s both;
animation-delay: calc(sibling-index() * 120ms);
}

@keyframes pop {
from { opacity: 0; transform: scale(0.4); }
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS sibling-index() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee