One way to use CSS countersand reset them each time it occurs h2is as shown below.
The property counter-resetin the selector h2sets the counter value h2to 1, and the counter value to h30 (default) every time an element is encountered h2.
A property counter-incrementin the selector h3increments the counter h3every time an element is encountered h3.
h2 {
counter-reset: h2 1 h3 0;
}
h2:before {
content: "1." counter(h2);
}
h3 {
counter-increment: h3;
}
h3:before {
content: "1." counter(h2)"." counter(h3);
}
<h2>Bananas</h2>
<h3></h3>
<h3></h3>
<h3></h3>
<h2>Apples</h2>
<h3></h3>
<h3></h3>
<h3></h3>
<h2>Oranges</h2>
<h3></h3>
<h3></h3>
<h3></h3>
Hide result
h2 , 1. , CSS :
h2 {
counter-reset: h3 0;
}
h2:before {
content: "1.1";
}
h3 {
counter-increment: h3;
}
h3:before {
content: "1.1." counter(h3);
}