Is the charset meta tag required with HTML5?

twiz picture twiz · Feb 3, 2013 · Viewed 16.9k times · Source

The W3C "HTML5 differences from HTML4" working draft states:

For the HTML syntax, authors are required to declare the character encoding.

What does "required" mean?

Obviously, a browser will still render HTML5 without the charset meta tag. If no encoding is specified, which encoding will a browser use?

Basically, I want to know if it is actually necessary to include <meta charset="">, or if 99% of the time browsers will use the correct encoding anyway.

Here is the link: http://www.w3.org/TR/html5-diff/#character-encoding

Answer

hrunting picture hrunting · Feb 3, 2013

It is not necessary to include <meta charset="blah">. As the specification says, the character set may also be specified by the server using the HTTP Content-Type header or by including a Unicode BOM at the beginning of the downloaded file.

Most web servers today will send back a character set in the Content-Type header for HTML text data if none is specified. If the web server doesn't send back a character set with the Content-Type header and the file does not include a BOM and the page does not include a <meta charset="blah"> declaration, the browser will have a default encoding that is usually based on the language settings of the host computer. If this does not match the actual character encoding of the file, then some characters will be displayed improperly.

Will browsers use the proper encoding 99% of the time? If your page is UTF-8, probably. If not, probably not.

The W3C provides a document outlining the precendence rules for the three methods that says the order is HTTP header, BOM, followed by in-document specification (meta tag).