Description
If present, <meta charset=...>
must occur within the first 1024 bytes of the HTML document per the HTML Standard: https://html.spec.whatwg.org/multipage/semantics.html#charset
Ideally, <meta charset>
is the very first element within the <head>
. This has been a best practice for a long time, e.g. recommended by HTML5 Boilerplate: https://github.com/h5bp/html5-boilerplate/blob/master/dist/doc/html.md#the-order-of-the-title-and-meta-tags
To guide developers towards adopting this best practice, Lighthouse could show a warning when <meta charset>
is not the first element within <head>
(document.head.firstElementChild
).
Relevant links:
- Twitter thread: https://twitter.com/hsivonen/status/1198618391042560000
- Chromium DevTools issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1028041