negative
Baseline 2023Newly available
Since September 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Thenegative descriptor of the@counter-style at-rule lets you define how negative counter values are represented when defining custom counter styles. The value of thenegative descriptor defines the symbols to be added before and after the counter representation when the counter's value is negative.
In this article
Syntax
/* One <symbol> value */negative: "--"; /* Adds '--' before if counter value is negative *//* Two <symbol> values */negative: "(" ")"; /* Adds '(- before and ')' after if counter value is negative */Values
Thenegative descriptor accepts up to two<symbol> values.
<symbol>If only one value is specified, it is added before the counter representation when the counter is negative. If two values are specified, the first one is added before and the second one is added after the counter representation when the counter is negative.
Description
If the counter value is negative, the specified<symbol> for thenegative descriptor is added before the counter representation, replacing the default- for negative values. The second<symbol>, if specified, is added after the counter representation.
Thenegative descriptor is relevant in two cases: if counter styles have thesystem value ofsymbolic,alphabetic,numeric, andadditive and the count is negative; and ifsystem value isextends and the extended counter style itself uses a negative sign. For systems that don't support negative counter values, specifying thenegative descriptor has no effect and is ignored.
Formal definition
| Relatedat-rule | @counter-style |
|---|---|
| Initial value | "-" hyphen-minus |
| Computed value | as specified |
Formal syntax
negative =
<symbol><symbol>?
<symbol> =
<string>|
<image>|
<custom-ident>
<image> =
<url>|
<image()>|
<image-set()>|
<cross-fade()>|
<element()>|
<gradient>
<image()> =
image(<image-tags>?[<image-src>? ,<color>?]!)
<image-set()> =
image-set(<image-set-option>#)
<cross-fade()> =
cross-fade(<cf-image>#)
<element()> =
element(<id-selector>)
<image-tags> =
ltr|
rtl
<image-src> =
<url>|
<string>
<image-set-option> =
[<image>|<string>][<resolution>||type(<string>)]?
<cf-image> =
[<image>|<color>]&&
<percentage [0,100]>?
<id-selector> =
<hash-token>
Examples
>Rendering negative counters
This exampleextends thedecimal list style. Thenegative descriptor is used to add(- and) before and after negative counter values.
HTML
<ol start="-3"> <li>Negative three</li> <li>Negative two</li> <li>Negative one</li> <li>Zero</li> <li>One</li></ol>CSS
@counter-style neg { system: extends decimal; negative: "(-" ")"; suffix: ": ";}ol { list-style: neg;}Result
The prefix and suffix listed as the value of thenegative descriptor are only added to the marker when the counter value is less than zero.
Specifications
| Specification |
|---|
| CSS Counter Styles Level 3> # counter-style-system> |
Browser compatibility
See also
@counter-styledescriptors:system,symbols,additive-symbols,prefix,suffix,range,pad,speak-as,fallback- List style properties:
list-style,list-style-image,list-style-position symbols()function to create anonymous counter styles- CSS counter styles module
- CSS lists and counters module