The CSS reference

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

  • Used to set a reset 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-reset - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari
    Browser deviation:
    • To work in IE, a DOCTYPE must be declared.

Possible counter-reset values:

counter-reset value Comments CSS
none Means no counters are reset. 2
[[identifier] [integer]] + ... Accepts one or more names of counters (identifiers), each one optionally followed by an integer. The integer gives the value that the counter is set to on each occurrence of the element. The default is 0. 2
inherit Will inherit the value from parent specification. 2

Property "counter-reset" example:

    <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) ") ";
     <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 id="ul2">
      <li>Link pseudo-classes:</li>
      <li>Dynamic pseudo-classes:</li>
      <li>Selecting a first child:</li>
      <li>Selecting on language:</li>

Javascript access:

// To SET values ([o] is the target object)
[o].style.counterReset="counter-reset 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.counterReset;
/* 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.