So this isn't a new trick by any means, but it sure is handy (Think outlines, book chapters, line numbering...) The more markup you can minimize via CSS the better, in my book.

Counter-increment CSS Property "The counter-increment property accepts one or more names of counters (identifiers), each one optionally followed by an integer. The integer indicates by how much the counter is incremented for every occurrence of the element. The default increment is 1. Zero and negative integers are allowed."

Fundamentally this property allows web developers to dynamically name html elements per element. I am using this to create line numbers for theme editor app


The counter-reset property specifies when the counter should be reset. The identifier in this property is just a matter of preference. A lot of examples I have run across use section or chapter. To use this effectively you need to specify a parent element with the counter-reset property and the child element that should be incremented with the counter-increment property.


body {
  counter-reset: section;

div:before {
  counter-increment: section;
  content: counter(section);
  <div>Some content goes here</div>
  <div>More content goes here</div>
  <div>Yep, more content</div>
1 Some content goes here 2 More content goes here 3 Yep, more content

Check out my jsfiddle for a demo! Dynamic Numbered CSS

« Previous Post
Firemin: The Firefox memory leak fixer app
Next Post »
How to prevent html textarea resizing using css

Join the conversation

comments powered by Disqus