Auto-generated header ids can contain invalid CSS selectors
Author: MarkvanMentsCreated Sep 27, 2021Updated Sep 28, 2026
LabelsBugKeepFeature: TOC
### What version of Hugo are you using (`hugo version`)?
### Does this issue reproduce with the latest release?
Yes - this is the latest version
If I have a markdown header which begins with a number Hugo generates an id beginning with a number. For example `## 1 Test` generates `
$ 88.1
1 Test…
`  According to w3.org (https://www.w3.org/TR/CSS21/syndata.html#characters) `In CSS, identifiers (including element names, classes, and IDs in selectors) … cannot start with a digit, two hyphens, or a hyphen followed by a digit.` This causes the error `Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#1-test' is not a valid selector.` if I try to do a `document.querySelector()` on this selector. In tests, this seems to be caused by the leading digit.  The querySelector code is used, for example, in a recent Pull Request on the Docsy theme (https://github.com/google/docsy/pull/506) This format of anchor is produced with both Blackfriday and Goldmark as the markup generator and is independent of the setting of `autoHeadingIDType`.Source: gohugoio/hugo