THE GITHTML FIELD GUIDE
Why CSS-generated section numbers disappear when copied
Numbers generated by CSS counters are presentation, so they may not survive copying, export, or alternative reading in the way authors expect. If a number is a stable identifier used in references, put it in the document content. Use counters only when their absence does not make a citation or instruction ambiguous.
Identify the specific failure
A heading can visibly read 4.2 without containing those characters in its text. A note that refers only to section 4.2 becomes difficult to follow when copied into another medium. Automatic visual numbering also changes when sections are rearranged.
Make a narrow correction
Use descriptive section names and stable fragment identifiers for navigation. If numbered references are required, include their approved labels explicitly and update references together. Avoid treating a generated position number as a permanent identifier.
- Determine whether generated numbers are decorative or used as substantive references.
- Keep stable labels and identifiers in the actual document when references depend on them.
- Test copied headings and citations after any section reorder.
<h2 id="retry-policy">4.2 Retry policy</h2>Separate a positional number from a stable citation label
Imagine a review note that says See 3.4, while the visible heading's number comes entirely from a CSS counter. When the heading is copied into a message, the number may not accompany its text in the same way. Even if it does in one browser, reordering sections can change the generated number. Add the descriptive title to the reference and use a stable fragment identifier so the reader has another way to locate the passage. Treat a counter as a presentation mechanism, not a permanent naming system.
A nested counter setup can also produce unexpected numbering after content is moved. The reset may live on a wrapper that was omitted from the export, or an increment may match more elements than the author intended. Inspect the reset, increment, and generated content together for one short section hierarchy. Check the first item after each reset and the transition into a nested level. Fixing the displayed numeral with a hard-coded pseudo-element can hide a broken counter scope without restoring the intended sequence.
If a formal report requires fixed numbered clauses, include the approved label in the actual heading text and maintain its cross-references deliberately. Avoid adding the same label both in text and through a counter, which would display it twice. A useful acceptance test copies a heading, its citation sentence, and an adjacent subheading into plain text, then asks whether the references remain unambiguous. Repeat after inserting a new section. The result should preserve meaning even when visual numbering changes or the reader uses a representation that handles generated content differently.
Verify the repaired artifact
Copy a heading and a cross-reference into plain text. They should still identify the same passage without consulting the styled page.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.