Elements such as <h1>, <h2> are not nested in a document. They appear as distinct elements but still represent a sort of hierarchy. Here’s how to prepend nested numbers to headings:
The h2 counter resets every time an h1 is found. Each <h2> in the document gets a number like x.y. relative to the <h1>.