You should always explicitly declare the character encoding of your HTML documents. If you don’t, you might witness unexpected behaviour.
This is the bare minimum I would use for a valid document:
Running it through the W3C Markup Validation Service, we can see that it’s fully valid HTML with no errors or warnings:
If you don’t include the
<meta charset="utf-8"> element, the Web Console in Firefox will show an error:
It’s still “valid” HTML if you omit it, but why make your page more fragile?
The MDN Web Docs explain the
This attribute declares the document’s character encoding. If the attribute is present, its value must be an ASCII case-insensitive match for the string “
If you’re also using non-ASCII characters in your CSS, it’s worth adding the
@charset at-rule to the top of your stylesheet as well:
The MDN Web Docs explain that this is
useful when using non-ASCII characters in some CSS properties, like .
If you have questions, feedback, or any other suggestions, please do email me. I'd love to hear from you!