πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

CSS Counters

Web Styles🟒 Free Lesson

Advertisement

CSS Counters

Automatic numbering, custom counters, and content generation.

Overview

CSS counters automatically number elements.

Key Concepts

  • counter-reset β€” Initialize a counter
  • counter-increment β€” Increment counter
  • counter() β€” Display counter value
  • counters() β€” Nested counters
  • content β€” Insert generated content

Code Examples

/* Ordered list with counters */
.list {
  counter-reset: item;
}

.list-item {
  counter-increment: item;
}

.list-item::before {
  content: counter(item) '. ';
  font-weight: bold;
}

/* Nested counters */
.nested-list {
  counter-reset: subitem;
}

.nested-list-item {
  counter-increment: subitem;
}

.nested-list-item::before {
  content: counter(item) '.' counter(subitem) ' ';
}

/* Roman numerals */
.roman-list {
  counter-reset: roman;
}

.roman-list-item {
  counter-increment: roman;
}

.roman-list-item::before {
  content: counter(roman, upper-roman) '. ';
}

/* Letters */
.letter-list {
  counter-reset: letter;
}

.letter-list-item {
  counter-increment: letter;
}

.letter-list-item::before {
  content: counter(letter, lower-alpha) ') ';
}

/* Complex numbering */
.article {
  counter-reset: section;
}

.article h2 {
  counter-increment: section;
}

.article h2::before {
  content: counter(section) '. ';
}

/* Step counter */
.steps {
  counter-reset: step;
}

.step {
  counter-increment: step;
  position: relative;
  padding-left: 60px;
}

.step::before {
  content: counter(step);
  position: absolute;
  left: 0;
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

/* Invoice numbering */
.invoice-items {
  counter-reset: invoice;
}

.invoice-item {
  counter-increment: invoice;
}

.invoice-item::before {
  content: 'Item ' counter(invoice) ': ';
  font-weight: bold;
}

Practice

Build a step-by-step wizard with CSS counter numbering.

⭐

Premium Content

CSS Counters

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
πŸ’ΌInterview Prep
πŸ“œCertificates
🀝Community Access

Already a member? Log in

Need Expert Web Development Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement