Favorites

sibling-count() CSS Function

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

The sibling-count() function returns the number of siblings of an element, including itself, useful for sizing items to fit.

☕
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-count() CSS function returns an integer giving the total number of children of the element's parent, including the element itself. If a list has five items, sibling-count() returns 5 for each of them. It is one of the tree-counting functions, together with sibling-index(), and its result can be used in calc() and other math functions.

Knowing how many siblings there are lets elements adapt to the size of their group. For example, each item can take an equal share of the width, items arranged in a circle can be spaced evenly at 360deg / sibling-count(), or a list can automatically use smaller text when it holds many items. Combined with sibling-index(), it is possible to calculate an element's relative position, such as calc(sibling-index() / sibling-count()), which runs from just above 0 to 1.

/* Equal-width segments, however many there are */
.segments span {
  width: calc(100% / sibling-count());
}

/* Spread items evenly around a circle */
.radial-menu a {
  rotate: calc(360deg / sibling-count() * sibling-index());
}

/* Fade from transparent to solid across the list */
.steps li {
  opacity: calc(sibling-index() / sibling-count());
}

Interactive Demo

  • 1
  • 2
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
Demo Code
HTML Code
<div class="demo-element">
	<ul><li>1</li><li>2</li></ul>
	<ul><li>1</li><li>2</li><li>3</li><li>4</li></ul>
	<ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li></ul>
</div>
CSS Code
.demo-element ul {
	display: flex;
	align-items: start;
	margin: 0 0 10px;
	padding: 0;
}
.demo-element li {
	box-sizing: border-box;
	padding: 4px;
	background: #4361ee;
	color: #fff;
	font-size: 13px;
	list-style: none;
	outline: 1px solid #fff;
	width: calc(260px / sibling-count());
}

Syntax

sibling-count() = sibling-count()

Values

  • (no arguments)The function takes no arguments. It returns an <integer>: the number of element children of the element's parent, including the element itself.

Example

<div class="wrap">
<h1>CSS sibling-count() examples</h1>
<div class="card">
<div class="bar"><span>1/3</span><span>2/3</span><span>3/3</span></div>
<div class="bar"><span>1/5</span><span>2/5</span><span>3/5</span><span>4/5</span><span>5/5</span></div>
<div class="bar"><span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span></div>
<div class="label">width: calc(100% / sibling-count())</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-count() examples */
.bar {
display: flex;
height: 44px;
margin-bottom: 8px;
border-radius: 8px;
overflow: hidden;
}

.bar span {
width: calc(100% / sibling-count());
display: grid;
place-items: center;
color: #fff;
font-size: 13px;
font-weight: 700;
background: hsl(calc(220deg + sibling-index() * 25deg) 70% 50%);
opacity: calc(0.4 + 0.6 * sibling-index() / sibling-count());
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS sibling-count() 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