:root { --section-prefix: ''; } main :is(h1, h2, h3, h4, h5, h6):not(.unnumbered)::before { padding-right: 1ex; } main h1:not(.unnumbered) { counter-increment: h1; } main h1 { counter-reset: h2 h3 h4 h5 h6; } main h1:not(.unnumbered)::before { content: var(--section-prefix) counter(h1); } main h2:not(.unnumbered) { counter-increment: h2; } main h2:not(.unnumbered)::before { content: var(--section-prefix) counter(h1) '.' counter(h2); } main h2 { counter-reset: h3 h4 h5 h6; } main h3:not(.unnumbered) { counter-increment: h3; } main h3 { counter-reset: h4 h5 h6; } main h3:not(.unnumbered)::before { content: var(--section-prefix) counter(h1) '.' counter(h2) '.' counter(h3); } main h4:not(.unnumbered) { counter-increment: h4; } main h4 { counter-reset: h5 h6; } main h4:not(.unnumbered)::before { content: var(--section-prefix) counter(h1) '.' counter(h2) '.' counter(h3) '.' counter(h4); } main h5:not(.unnumbered) { counter-increment: h5; } main h5 { counter-reset: h6; } main h5:not(.unnumbered)::before { content: var(--section-prefix) counter(h1) '.' counter(h2) '.' counter(h3) '.' counter(h4) '.' counter(h5); } main h6:not(.unnumbered) { counter-increment: h6; } main h6:not(.unnumbered)::before { content: var(--section-prefix) counter(h1) '.' counter(h2) '.' counter(h3) '.' counter(h4) '.' counter(h5) '.' counter(h6); }