CKTIS / CSS
@counter-style — a custom numbering system
The @counter-style rule defines a named representation for counter values, consumed by list-style-type or the counter() and counters() functions.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
@counter-style <counter-style-name> {
[ system: <counter-system>; ] ||
[ symbols: <counter-symbols>; ] ||
[ additive-symbols: <additive-symbols>; ] ||
[ negative: <negative-symbol>; ] ||
[ prefix: <prefix>; ] ||
[ suffix: <suffix>; ] ||
[ range: <range>; ] ||
[ pad: <padding>; ] ||
[ speak-as: <speak-as>; ] ||
[ fallback: <counter-style-name>; ]
}@counter-style <counter-style-name> { <declaration-list> } creates a named counter style. The system descriptor chooses an algorithm such as numeric, alphabetic, cyclic, fixed, symbolic, additive, or extends. symbols supplies symbols for most systems, while additive-symbols supplies weight-symbol pairs for an additive system. These are rule descriptors, not ordinary element properties.
Typical uses are list markers, heading numbers produced with counter(), and hierarchical labels built with counters(). prefix and suffix surround a representation, negative handles negative values, pad extends short output, range limits representable values, and fallback names another style when this system cannot render a number.
A numeric system needs at least two symbols and treats them as digits in a positional numeral system; "0" "1" therefore creates binary notation. An invalid definition or an out-of-range value falls back rather than inventing output. The example reads the real CSSCounterStyleRule, its descriptors, and the list’s computed list-style-type, verifying that the named definition is selected.
Examples
const style = document.createElement('style');
style.textContent = `@counter-style binary { system: numeric; symbols: "0" "1"; suffix: ". "; fallback: decimal; }
ol { list-style-type: binary; }`;
document.head.append(style);
const list = document.createElement('ol');
list.innerHTML = '<li>one</li><li>two</li><li>three</li>';
document.body.append(list);
const rule = style.sheet.cssRules[0];
console.log('rule=' + rule.constructor.name + '; system=' + rule.system + '; symbols=' + rule.symbols + '; used=' + getComputedStyle(list).listStyleType);Result
rule=CSSCounterStyleRule; system=numeric; symbols="0" "1"; used=binary
The @counter-style rule defines a named representation for counter values, consumed by list-style-type or the counter() and counters() functions.