The CSS reference

"counter-increment" - css property (v. css 2)

  • Used to set a counting integer value for several counters that can be used by the 'content' property.
  • Initial value: none
  • The property is not inherited
  • HTML usage: all elements
  • The keywords 'none', 'inherit' and 'initial' must not be used as counter names.
  • 'Initial' is reserved for future use.
  • Browsers that support the counter-increment - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari
    Browser deviation:
    • To work in IE, a DOCTYPE must be declared.

Possible counter-increment values:

counter-increment value Comments CSS
none Means no counters are incremented. 2
[[identifier] [integer]] + ... 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. 2
inherit Will inherit the value from parent specification. 2

Property "counter-increment" example:

<!DOCTYPE HTML >
<html>
  <head>
    <style type="text/css">
      body { counter-reset: chapter; }
      ul { counter-increment: chapter;
        counter-reset: section; }
      li { display: block;
        position: relative;
        left: 20px; counter-increment: section; }
     #ul1:before {
        content: counter(chapter, upper-roman)
          ") CSS Pseudo Elements Selectors"  ;}
    #ul2:before {
        content: counter(chapter, upper-roman)
          ") Four types of Pseudo-classes"  ;}
      li:before {
        content: counter(section, lower-roman) ") ";
      }
    </style>
  </head>
  <body>
     <ul id="ul1">
      <li>The :first-line pseudo-element</li>
      <li>The :first-letter pseudo-element</li>
      <li>The :before pseudo-elements</li>
      <li>The :after pseudo-elements</li>
    </ul>
    <ul id="ul2">
      <li>Link pseudo-classes:</li>
      <li>Dynamic pseudo-classes:</li>
      <li>Selecting a first child:</li>
      <li>Selecting on language:</li>
    </ul>
  </body>
</html>

Javascript access:

// To SET values ([o] is the target object)
[o].style.counterIncrement="counter-increment values"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null)
// To GET the property value:;
var value=cStyle.counterIncrement;
/* The returned value is not cross-browser reliable. The value can vary in accuracy and notation, which depends on the browser, whether the value is preset or not and which option that was used to set the value.*/
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.