h1 { /* must reset here */ counter-reset: chapter {{ page.chapter }}; } h1:before { /* and must reset again here */ counter-reset: chapter {{ page.chapter }}; content: "Chapter " counter(chapter); display: block; } h2 { /* must increment here */ counter-increment: section; counter-reset: subsection; } h2:before { /* and must reset again here */ counter-reset: chapter {{ page.chapter }}; content: counter(chapter) "." counter(section) ; display: inline; margin-right: 1em; } h2:after { /* can only have one counter-reset per tag, so can't do it in h2/h2:before... */ counter-reset: example; } h3 { /* must increment here */ counter-increment: subsection; } h3:before { /* and must reset again here */ counter-reset: chapter {{ page.chapter }}; content: counter(chapter) "." counter(section) "." counter(subsection); display: inline; margin-right: 1em; } h3[id*='example'] { /* must increment here */ counter-increment: example; display: inline; } h3[id*='example']:before { /* and must reset again here */ counter-reset: chapter {{ page.chapter }}; content: "Example " counter(chapter) "." counter(section) "." counter(example); display: inline; margin-right: 1em; } .no-numbering, .no-numbering:before, .no-numbering:after { content: normal; counter-reset: none; counter-increment: none; }