Skip to content

Instantly share code, notes, and snippets.

@James-Ansley
Last active July 20, 2024 00:01
Show Gist options
  • Save James-Ansley/4481b5874ed0027632752bfa4083f799 to your computer and use it in GitHub Desktop.
Save James-Ansley/4481b5874ed0027632752bfa4083f799 to your computer and use it in GitHub Desktop.
Adds counters to section headings
h2 { counter-increment: h2; counter-reset: h3; }
h3 { counter-increment: h3; counter-reset: h4; }
h4 { counter-increment: h4; counter-reset: h5; }
h5 { counter-increment: h5; counter-reset: h6; }
h6 { counter-increment: h6; }
h2:before { content: counter(h2) ": " }
h3:before { content: counter(h2) "." counter(h3) ": " }
h4:before { content: counter(h2) "." counter(h3) "." counter(h4) ": " }
h5:before { content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ": " }
h6:before { content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ": " }
/* For those websites confused enough to use h1 tags for sections */
h1 { counter-increment: h1; counter-reset: h2; }
h2 { counter-increment: h2; counter-reset: h3; }
h3 { counter-increment: h3; counter-reset: h4; }
h4 { counter-increment: h4; counter-reset: h5; }
h5 { counter-increment: h5; counter-reset: h6; }
h6 { counter-increment: h6; }
h1:before { content: counter(h1) ": " }
h2:before { content: counter(h1) "." counter(h2) ": " }
h3:before { content: counter(h1) "." counter(h2) "." counter(h3) ": " }
h4:before { content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ": " }
h5:before { content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ": " }
h6:before { content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ": " }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment