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,".") ": ";
}

  

 

 

 

back to top