CSS Properties: How to set a number sections and sub-sections with section?

Go to Exercise page


HTML Code:

<!DOCTYPE html>
<title>How to set a number sections and sub-sections with section</title>
<style type="text/css">
body {
 counter-reset: section;
h1 {
 counter-reset: subsection;
h1:before {
 counter-increment: section;
 content: "Section " counter(section) ". ";
h2:before {
 counter-increment: subsection;
 content: counter(section) "." counter(subsection) " ";
<h1>HTML tutorials</h1>
<h2>HTML Tutorial</h2>
<h2>CSS Tutorial</h2>
<h2>HTML5 Tutorial</h2>
<h1>Database tutorials</h1>
<h2>HTML CSS</h2>

Live Demo:

See the Pen counter-reset-answer by w3resource (@w3resource) on CodePen.

See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes Yes

Go to Exercise page

What is the difficulty level of this exercise?