CSS counters function similarly to “variables”, where their values can be incremented by CSS rules to track their usage frequency.
To employ CSS counters, the following properties are utilized:
To utilize a CSS counter, it must be initially established with counter-reset.
The subsequent example initiates a counter for the page within the body selector, then increments the counter value for each <h2> element, prepending “Section <value of the counter>:” to the start of each <h2> element.
Example
| 
 body {  | 
In the given instance, a single counter is established for the page (referred to as “section”), alongside a separate counter for each <h1> element (referred to as “subsection”).
The “section” counter will be incremented for every <h1> element, denoting “Section <value of the section counter>.”, while the “subsection” counter will be incremented for each <h2> element, representing “<value of the section counter>.<value of the subsection counter>”.
Example
| 
 body {  | 
A counter can be advantageous for creating outlined lists as a new instance of a counter is automatically generated in child elements. In this scenario, we utilize the counters() function to inject a string between various levels of nested counters.
Example
| 
 ol {  | 
| 
 Property  | 
 Description  | 
| 
 content  | 
 Utilized with the `::before` and `::after` pseudo-elements to insert generated content.  | 
| 
 counter-increment  | 
 Increases one or more counter values.  | 
| 
 counter-reset  | 
 Creates or resets one or more counter values.  | 
| 
 counter()  | 
 Retrieves the current value of the specified counter.  |