CSS | Counters
Counters in CSS are basically variables which can be used for numbering and values of CSS counters may be incremented by CSS rules. For example, CSS counters can be used to increment the numbering of the headings automatically. In HTML, <ol> tag is used to give the ordered numbers to list items but CSS contains counter to give order elements in some other fashion.
CSS counters properties: CSS counters contains the following properties:
- counter-reset: It is used to reset a counter.
- counter-increment: It basically increments a counter value.
- content: It is used to generate content.
- counter() or counters() function: The value of a counter can be displayed using either the counter() or counters() function in a content property. These two functions basically used to add the value of a counter to the element.
Initialization the CSS Counter: To use CSS counter property firstly it must be created with the counter-reset property and the first step is resetting the counter. The myCounter by default initialized to a value 0(zero) with the counter-reset property.
Incrementation and Use of CSS Counter: To incrementing the counter use CSS counter-increment property.
The counter() or counters() function in a content is used to display the content in a particular order.
Nested CSS counters: The counter within a counter is known as nested counter. Nested counter are used to create heading and subheadings. This example shows the use of CSS counters with nested tags. Different counter are used for different type of tags.
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.