CSS counter-increment Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Counters

What You’ll Learn

The counter-increment property increases a CSS counter — useful for automatic section numbers, custom lists, and step indicators.

01

Increment

Increase counter.

02

CSS Counters

Named variables.

03

Default none

No increment.

04

With content

Display numbers.

05

counter-reset

Set start value.

06

Custom Lists

Beyond ol/ul.

Definition and Usage

The counter-increment CSS property increases the value of a CSS counter. Counters are variables maintained by CSS whose values can be incremented or decremented by CSS rules. They are useful for creating complex lists, numbering headings, and other content that requires incremental numbering.

Typically you combine three pieces: counter-reset to initialize, counter-increment on elements that should advance the count, and content: counter(name) in a pseudo-element to show the number.

💡
Beginner Tip

Increment happens when the element is rendered. Put counter-increment on the same element (or its ::before) where you display the counter value for predictable numbering.

📝 Syntax

The syntax lets you specify the counter name and how much to increment:

syntax.css
selector {
  counter-increment: counter-name increment-value;
}

Basic Example

counter-increment-section.css
body {
  counter-reset: section;
}

h2::before {
  counter-increment: section;
  content: "Section " counter(section) ": ";
}
1. counter-reset 2. counter-increment 3. counter() in content

Syntax Rules

  • The initial value is none — no counter is incremented.
  • Omitting the increment amount defaults to 1.
  • Counter names are custom identifiers like section or item.
  • Use negative values to decrement: counter-increment: step -1;.
  • Works with counter-reset and content: counter().

⚡ Quick Reference

QuestionAnswer
Initial valuenone
Applies toAll elements
InheritedNo
AnimatableNo
Default increment1 when amount is omitted

💎 Property Values

The counter-increment property accepts a counter name and optional integer step.

ValueDescription
counter-nameThe name of the counter you want to increment. If the counter does not exist, it will be created.
increment-valueAn integer that specifies how much the counter increases by. The default value is 1.
noneNo counter is incremented (initial value).

The CSS Counter System

Property / FunctionRole
counter-resetCreates or resets a counter to a starting value (often 0)
counter-incrementIncreases the counter (this property)
counter(name)Displays the current counter value in content
counters(name, sep)Displays nested counter values, e.g. 1.2.3

👀 Live Preview

Each heading is prefixed with “Section 1:”, “Section 2:”, etc. using counter-increment and counter(section).

Introduction

This is the introduction section.

Usage

This section explains counter-increment.

Conclusion

This is the conclusion section.

Examples Gallery

Try numbered sections, custom list counters, step-by-two numbering, and nested chapter counters.

🔢 Basic Counter Increment

Start with the reference example — auto-numbered h2 section headings.

Example 1 — Numbered Section Headings

Prefix each h2 with “Section N:” using a CSS counter.

counter-increment-section.html
<style>
  body {
    counter-reset: section;
  }
  h2::before {
    counter-increment: section;
    content: "Section " counter(section) ": ";
  }
</style>

<h2>Introduction</h2>
<h2>Usage</h2>
<h2>Conclusion</h2>
Try It Yourself

How It Works

Each h2::before increments the section counter and displays its current value before the heading text.

Example 2 — Custom Numbered List

Number list items with a counter instead of default <ol> markers.

counter-increment-list.css
.steps {
  list-style: none;
  counter-reset: step;
  padding-left: 0;
}

.steps li {
  counter-increment: step;
}

.steps li::before {
  content: counter(step) ". ";
  font-weight: bold;
  color: #2563eb;
}
Try It Yourself

How It Works

Each li increments the step counter; ::before shows the number with custom styling.

🛠 Advanced Patterns

Control increment steps and build nested numbering schemes.

Example 3 — Increment by 2

Skip numbers by setting an explicit increment value.

counter-increment-by-2.css
.even-steps li {
  counter-increment: even 2;
}

.even-steps li::before {
  content: "Step " counter(even) ": ";
}
Try It Yourself

How It Works

counter-increment: even 2 adds 2 each time, producing 2, 4, 6 instead of 1, 2, 3.

Example 4 — Nested Chapter & Section Counters

Use nested counters with counters() for outline-style numbering like 1.1, 1.2.

counter-increment-nested.css
.outline {
  counter-reset: chapter;
}

.outline h2 {
  counter-increment: chapter;
  counter-reset: section;
}

.outline h2::before {
  content: "Chapter " counter(chapter) ": ";
}

.outline h3 {
  counter-increment: section;
}

.outline h3::before {
  content: counter(chapter) "." counter(section) " ";
}
Try It Yourself

How It Works

Each h2 increments chapter and resets section. Each h3 increments section and displays chapter.section with two counter() values.

🧠 How counter-increment Works

1

counter-reset initializes

A parent sets the starting value with counter-reset: section;.

Prerequisite
2

counter-increment runs

Each matching element increases the counter by 1 (or your custom step).

CSS rule
3

counter() displays value

Use content: counter(section) in a pseudo-element to show the number.

Display
=

Automatic numbering

Headings and list items get dynamic numbers without manual HTML editing.

Modern Browser Support

The counter-increment property is widely supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera.

Baseline · Modern browsers

CSS counters everywhere

All major browsers support counter-increment as part of the CSS Counter Styles module.

99% Modern browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
counter-increment property 99% supported

Bottom line: Use CSS counters reliably in modern browsers. Test nested counter layouts in Safari if your design depends on them.

Conclusion

The counter-increment property is a powerful feature in CSS that allows for sophisticated control over content numbering and ordering. By using it in combination with counter-reset and the content property, you can create dynamic and automatically numbered elements in your web pages.

Experiment with different counters and increment values to see how they can enhance your designs and user interfaces.

💡 Best Practices

✅ Do

  • Always counter-reset before incrementing for predictable starts
  • Display counters with content: counter(name)
  • Use meaningful counter names like section or chapter
  • Reset nested counters on parent headings for outline numbering
  • Prefer semantic HTML (<ol>) when accessibility is critical

❌ Don’t

  • Rely on CSS counters alone for essential document structure
  • Forget to increment before displaying — order matters
  • Use counters for content screen readers must announce as list items
  • Mix up counter names across unrelated components
  • Expect counters to work without content or counter()

Key Takeaways

Knowledge Unlocked

Five things to remember about counter-increment

Use these points when building automatic numbering.

5
Core concepts
02

Default none

No increment.

Default
🖌 03

Step of 1

Default amount.

Syntax
📝 04

With reset

counter-reset first.

Tip
🛸 05

With content

counter() display.

Related

❓ Frequently Asked Questions

counter-increment increases the value of a named CSS counter by a specified amount. Counters are variables maintained by CSS for automatic numbering.
The initial value is none, which means no counter is incremented.
Use counter-reset to set a starting value, counter-increment to increase the counter on each matching element, and content: counter(name) in ::before or ::after to display the number.
If you omit the increment amount and write counter-increment: section, the counter increases by 1 each time.
Yes. If the named counter does not exist yet, it will be created when you first increment it. Still, counter-reset is recommended for predictable starting values.

Practice in the Live Editor

Open the HTML editor, set counter-increment: section on headings, and preview automatic section numbering.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful