In this example, we display a sequence of numbers counting backward. To do this, we use a counter to display numbers starting from 100 and decreasing by 7 each time.
HTML
<div>
<i></i><i></i><i></i><i></i><i></i><i></i><i></i> <i></i><i></i><i></i><i></i
><i></i><i></i><i></i> <i></i><i></i><i></i><i></i><i></i><i></i><i></i>
<i></i><i></i><i></i><i></i><i></i><i></i><i></i>
</div>
CSS
We set the initial value of the counter named sevens to 100 by using counter-reset. Then, for each <i>, we decrease the counter by 7.
To set the first count at 100, we target the first <i> element by using the :first-of-type pseudo-class and setting counter-increment: none;. Additionally, the content property is used in the ::before pseudo-element to display the value of the counter using the counter() function.
div {
counter-reset: sevens 100;
}
i {
counter-increment: sevens -7;
}
i:first-of-type {
counter-increment: none;
}
i::before {
content: counter(sevens);
}
Result
Had we not used counter-reset (or counter-set) to create the counter and set the value to 100, the sevens counter would still have been created, but with an initial value 0.