Choose an example

1. Divide the row by the count

sibling-count() returns how many siblings an element has, so a single rule can split a row into equal parts without knowing how many parts there will be. The width subtracts the gaps first, so the items still fit exactly however many there are — compare the five-item and eight-item rosters below.

.item {
  inline-size: calc(
    (100% - (sibling-count() - 1) * 0.75rem) / sibling-count()
  );
}

5 siblings

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

8 siblings

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8