This page provides a simple framework in which we can see the use of JavaScript to add numbers to all the headings automatically.
The absence of CSS is deliberate — the aim is to focus on the Markup and scripting.
The core script is a slightly modified version of that written by Liam Bennett which he wrote to originally to add heading numbers to Google Docs.
Here's some short text underneath that heading.
And a bit more text here too, but this one has sub sections!
An extremely short subsection.
An ever shorter one.
A gratuitous use of an h1 heading merely to show another correctly numbered heading.