InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

CSS

    CSS selectors

    • CSS selectors

    CSS properties

    • CSS properties

    CSS cookbooks

    • !important annotation
    • Align div in center horizontally
    • Align div in center vertically
    • Align multiple divs horizontally
    • Align text in center horizontally
    • CSS - drop cap effect
    • CSS - enlarge image on hover
    • CSS - round toggle switch using checkbox and label
    • CSS automatic table row numbering
    • CSS circle and oval
    • CSS clearfix - clear float automatically using ::after
    • CSS counters
    • CSS nested counters
    • CSS3 gradients
    • Create CSS triangles
    • First letter capital and bigger
    • How to display text on image using css
    • Install sass on Mac or Linux using ruby gem
    • Place a div in bottom right corner of browser
    • Test site css, javascript, html in old IEs
    • csslint
    • inherit value
    • initial value
    • inline-block and baseline alignment
    • margin collapsing
    • node-sass quick start tutorial on Linux and Mac
    • unset value
    • web typography
     
    • Home
    • > Tutorials
    • > CSS

    CSS automatic nested numbering for headings

    on Mar 26, 2016

    CSS counters are variables maintained by CSS whose values may be incremented by CSS rules to track how many times they are used. Here is code example to automatically display numbering before h2 and child h3 tags. For a simple example please visit CSS counters – automatic numbering before h2.

    Here is code flow on how css nested numbering can be done on h2 and h3.

    1. Use counter h2count and h3count for counting h2 and h3.
    2. Reset h3 (counter-reset: h3count;) on every occurrence of h2.
    3. Increment h2count (counter-increment: h2count;) on every occurrence of h2 and similarly increment h3count on on every occurrence of h3.
    4. Display h2count before (using ::before) be fore h2
    5. Display a combination of h2count and h3count before h3.

    Example – automatic nested counters for h2 and child h3 tags

    <style type="text/css">
    body { counter-reset: h2count; }
    h2 {
      counter-increment: h2count;
      counter-reset: h3count;
    }
    h2::before {
      content: counter(h2count) ". ";
    }
    h3 {counter-increment: h3count;}
    h3::before {
      content: counter(h2count) "." counter(h3count) ". ";
    }
    </style>
    
    <h2>First h2</h2>
      <h3>first h3</h3><h3>second h3</h3>
    <h2>Second h2</h2>
      <h3>first h3</h3><h3>second h3</h3><h3>third h3</h3>
    <h2>Third h2</h2>
    refresh done
    try it online

    Suggested posts:

    1. Linux/Unix history with date and time
    2. CSS counters – automatic numbering before h2
    3. CSS – align text in center horizontally
    4. Make an element draggable using Vanilla Javascript
    5. Javascript – catch errors using window.onerror
    6. CSS selector specificity
    7. Javascript – how to view text inside DOM element
    8. Csslint – quick command-line tutorial and how to use it for pre-deployment sanity check
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged CSS, CSS cookbook, Tutorials
    • Browse content
    • Article Topics
    • Article archives
    • Contact Us
    Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

    Copyright © 2025 InfoHeap.

    Powered by WordPress