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.
- How to override the CSS properties of a class using another CSS class ?
- Difference between bootstrap.css and bootstrap-theme.css
- CSS Float
- CSS | Margins and Padding
- CSS | border-top-width Property
- Making a div vertically scrollable using CSS
- CSS | Percentage Value
- What is the difference between “word-break: break-all” versus “word-wrap: break-word” in CSS ?
- How to hide an element when printing a web page using CSS?
- CSS | :root Selector
- CSS | isolation Property
- How to prevent parents of floated elements from collapsing in CSS?
- CSS | Pagination
- HTML | Responsive full page image using CSS
- CSS | :only-of-type Selector
- CSS | column-rule-width Property
- CSS | word-spacing Property
- CSS | animation-delay Property
- CSS | Centering Elements
- CSS | margin-top 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