</> Code Corner

CSS · CSS Tutorial · Lesson 36

CSS Counters

Automatic numbering with CSS variables-like counters.

CSS counters are "variables" maintained by CSS whose values can be incremented by CSS rules to track how many times they are used.

Example

<style>
body { counter-reset: section; }
h2::before {
  counter-increment: section;
  content: "Section " counter(section) ": ";
  color: #04AA6D;
}
</style>
<h2>HTML Tutorial</h2>
<h2>CSS Tutorial</h2>
<h2>JavaScript Tutorial</h2>
Property / function Use
counter-reset Creates or resets a counter
counter-increment Increments a counter
content Inserts generated content
counter() / counters() Adds the counter value to an element

Keep reading “CSS Counters”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋