XML technologies / CSS / Advanced websites with CSS / CSS property reference / counter-increment
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
The property counter-increment specifies which element activates a counter and how much it increases for each element.
Nested elements automatically create a hierarchical counter, with a separate counter at each structural level.
Inherited: no
See also: content, counter-reset
Values
A counter name, optionally followed by a positive or negative integer. The integer specifies how much the counter increases (positive value) or decreases (negative value) when it encounters the element. To define several counters for one element, give their names and optional increments separated by spaces. The default value none is also supported, but has no practical use.
Default value: none
Compatibility
CSS version: 2
Not supported by any current browser.
Examples
The following rule counts the document’s <h1> tags and automatically displays a chapter number at the start of each first-level heading:
h1 {
counter-increment: chapter;
}
h1:before {
content: "Kapitel " counter(chapter) " - ";
}The following rules use a counter for all div elements and display its value in the accompanying headings. The counter output uses the format counters(), so nested div elements are numbered hierarchically.
div {
counter-increment: division;
}
div > h1:before {
content: "Abschnitt " counters(division,".") ": ";
}
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg