sibling-count() CSS Function
The sibling-count() function returns the number of siblings of an element, including itself, useful for sizing items to fit.
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
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
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.
Desktop





Tablets & Mobile





