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.
- AngularJS | Scope
- CSS | 4 Digit Hex Color
- CSS | saturate() Function
- HTML | canvas strokeText() Method
- HTML | DOM Image complete Property
- HTML | DOM Input Image name Property
- HTML | Flip a card
- HTML | <object> vspace Attribute
- CSS | @page rule
- CSS | 6 Digit Hex Color
- CSS | Grid Inspector
- HTML | <input> formnovalidate Attribute
- HTML | DOM Output name Property
- HTML | DOM Input Image formTarget Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai