Code snippet: Automatic Header Numbering Pure CSS

body {
    counter-reset: section;
}

h2 {
    counter-reset: subsection;
}

h3 {
    counter-reset: subsubsection;
}

h2:before {
    counter-increment: section;
    content: counter(section) ". ";
}

h3:before {
    counter-increment: subsection;
    content: counter(section) "." counter(subsection) " ";
}

h4:before {
    counter-increment: subsubsection;
    content: counter(section) "." counter(subsection) "." counter(subsubsection) " ";
}

<h1>Title</h1>
<h2>Content-Section 1</h2>
<h3>Subsection 1</h3>
<h3>Subsection 2</h3>
<h4>SubSubsection 1</h4>
<h2>Content-Section 1</h2>
<h3>Subsection 1</h3>
<h4>SubSubsection 1</h4>
<h4>SubSubsection 2</h4>
<h3>Subsection 2</h3>
<h3>Subsection 3</h3>
<h4>SubSubsection 1</h4>

Title

1. Content-Section 1

1.1 Subsection 1

1.2 Subsection 2

1.2.1 SubSubsection 1

2. Content-Section 1

2.1 Subsection 1

2.1.1 SubSubsection 1

2.1.2 SubSubsection 2

2.2 Subsection 2

2.3 Subsection 3

2.3.1 SubSubsection 1

Author: Angelique Dawnbringer Published: 2011-11-01 00:00:00 Keywords:
  • Code snippet
  • CSS
  • Automatic Header Numbering
Modified: 2017-07-24 12:19:48