The@counter-style
CSS at-rule lets you define counter styles that are not part of the predefined set of styles. An @counter-style
rule defines how to convert a counter value into a string representation.
@counter-style thumbs { system: cyclic; symbols: "\1F44D"; suffix: " "; } ul { list-style: thumbs; }
The initial version of CSS defined a set of useful counter styles. However, although more styles were added to this set of predefined styles over the years, this system proved too restrictive to fulfill the needs of worldwide typography. The @counter-style
at-rule addresses this shortcoming in an open-ended manner, by allowing authors to define their own counter styles when the pre-defined styles aren't fitting their needs.
Each @counter-style
is identified by a name and has a set of descriptors.
system
negative
prefix
suffix
range
pad
fallback
symbols
@counter-style
rule uses images instead of character symbols.@counter-style winners-list { system: fixed; symbols: url(gold-medal.svg) url(silver-medal.svg) url(bronze-medal.svg); suffix: " "; }
additive-symbols
speak-as
@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>; ] }where
<counter-style-name> = <custom-ident>
@counter-style circled-alpha { system: fixed; symbols: Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ; suffix: " "; }
The above counter style rule can be applied to lists like this:
.items { list-style: circled-alpha; }
Which will produce lists like this:
Ⓐ One
Ⓑ Two
Ⓒ Three
Ⓓ Four
Ⓔ FIve
....
...
Ⓨ Twenty Five
Ⓩ Twenty Six
27 Twenty Seven
28 Twenty Eight
29 Twenty Nine
30 Thirty
See more examples on the demo page.
Specification | Status | Comment |
---|---|---|
CSS Counter Styles Level 3 The definition of 'counter-style' in that specification. | Candidate Recommendation | Initial definition. |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | No | ? | 33 | No | No | No |
additive-symbols |
No | ? | 33 | No | No | No |
fallback |
No | ? | 33 | No | No | No |
negative |
No | ? | 33 | No | No | No |
pad |
No | ? | 33 | No | No | No |
prefix |
No | ? | 33 | No | No | No |
range |
No | ? | 33 | No | No | No |
speak-as |
No | ? | 33 | No | No | No |
suffix |
No | ? | 33 | No | No | No |
symbols |
No | ? | 33 | No | No | No |
system |
No | ? | 33 | No | No | No |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | Opera Android | iOS Safari | Samsung Internet |
---|---|---|---|---|---|---|---|
Basic support | No | ? | ? | 33 | No | No | ? |
additive-symbols |
No | ? | ? | 33 | No | No | ? |
fallback |
No | ? | ? | 33 | No | No | ? |
negative |
No | ? | ? | 33 | No | No | ? |
pad |
No | ? | ? | 33 | No | No | ? |
prefix |
No | ? | ? | 33 | No | No | ? |
range |
No | ? | ? | 33 | No | No | ? |
speak-as |
No | ? | ? | 33 | No | No | ? |
suffix |
No | ? | ? | 33 | No | No | ? |
symbols |
No | ? | ? | 33 | No | No | ? |
system |
No | ? | ? | 33 | No | No | ? |
none
as a value of the system
and fallback
descriptors of @counter-style
, which as per spec should result in an invalid at-rule. Firefox's new parallel CSS engine (also known as Quantum CSS or Stylo, planned for release in Firefox 57) aims to fix this (bug 1377414).list-style
, list-style-image
, list-style-position
, list-style-type
symbols()
, the functional notation creating anonymous counter styles.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/@counter-style