Skip to content
View in the app

A better way to browse. Learn more.

OKCCN - XenForo & IPS Plugin Marketplace

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
  • Language

Featured Replies

  • Administrators

CSS Counters


CSS Counters

With CSS counters, you can create dynamic numbering of elements (like headings, sections, or list items) without using JavaScript.

CSS counters are "variables" maintained by CSS, and their values can be incremented (or decremented) by CSS rules.

Pizza

Hamburger

Hotdogs


CSS Automatic Numbering With Counters

CSS counters are like "variables". The variable values can be incremented (or decremented) by CSS rules.

To work with CSS counters we will use the following properties:

  • counter-reset - Creates or resets a counter
  • counter-increment - Increments or decrements a counter
  • content - Inserts generated content
  • counter() - Adds the value of a counter to an element

To use a CSS counter, it must first be created with the counter-reset property.


CSS Increase and Decrease Counter

The following example creates a counter for the page (in the body selector), then it increments the counter value by 1 for each <h2> element:

Example

body {
  counter-reset: section;
}

h2::before {
  counter-increment: section;
  content: "Section " counter(section) ": ";
}
Try it Yourself »

Decrementing a Counter

The counter-increment property has a second parameter. The default value is 1. To decrease the counter value, you can set it to -1.

Example

body {
  counter-reset: section;
}

h2::before {
  counter-increment: section -1;
  content: "Section " counter(section) ": ";
}
Try it Yourself »


Incrementing by Custom Values

You can increment the counter by any value. Here we increment by 2:

Example

body {
  counter-reset: section;
}

h2::before {
  counter-increment: section 2;
  content: "Section " counter(section) ": ";
}
Try it Yourself »



Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.