v6.0.0-beta.5
  • Home
  • Tokens
  • Layout
  • Utilities
    • Click Area
    • Container
    • Counted
    • Dimensions
    • Hover Group
    • Indexed
    • Margin
    • No Print
    • Typography
    • Visually Hidden
    • Z-Index
  • Guides
  • home
  • /
  • utilities
  • /
  • Counted
Source

Counted

The Counted utility automatically sets a CSS custom property with the number of direct children an element has. This enables dynamic styling based on child count without requiring JavaScript, making it useful for adaptive layouts that need to respond to the number of items they contain.

Usage

Apply the .counted class to a parent element, and it will automatically provide a --count custom property that contains the number of direct children (up to 10). This count can then be used in CSS calculations or other layout components.

<div class="counted">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
  <!-- --count will be set to 3 -->
</div>

The utility works particularly well with layout components like the switcher layout, where you can use var(--count) in calculations to create adaptive behavior based on the number of child elements.

Custom Properties (Read-only)

Property Range Description
--count 1-10 The number of direct children
← utilities: Container utilities: Dimensions →
© Crinkles.
Powered by: 11ty & Feo.css | Github