Summarized test results:
Character encoding (HTML5)

Intended audience: users, XHTML/HTML coders (using editors or scripting), script developers (PHP, JSP, etc.), CSS coders, Web project managers, and anyone who wants to know how character encoding detection works in current browsers.

Updated

These tests check whether user agents recognise character encoding declarations for HTML5 documents. These test pages have HTML syntax and are served as text/html.

Note that these test results are for released versions of the browsers tested. Versions that are still in development may provide better support for these features. The tests do not use any vendor prefixes.

Results

To see the test, click on the link in the left-most column. To see detailed results for a single test, click on the link in the right-most column. To submit test data for a single test, click on the link in the right-most column and then follow the link on that page.

The tables show the latest results from the W3C Test Framework. Below the tables are summaries of the results at a given date. The table data may be more up-to-date than the summary. The tables may also contain some incorrectly scored tests, and tests that relate to non-released versions of browsers. These are not included in the summary.

Basics

Assertion Gecko Presto Trident WebKit Detailed results
HTTP charset Setting the HTTP header charset declaration will affect the encoding of a page.
UTF-16LE BOM A page with no encoding declarations, but with a UTF-16 little-endian BOM will be recognized as UTF-16.
UTF-16BE BOM A page with no encoding declarations, but with a UTF-16 big-endian BOM will be recognized as UTF-16.
XML declaration [Exploratory test] Setting the encoding in the XML declaration will not affect the encoding of a page served as text/html.
meta content attribute Setting the encoding in the meta content attribute will affect the encoding of a page served as text/html.
meta charset attribute Setting the encoding in the meta charset attribute will affect the encoding of an HTML5 page.
charset on an a element [Exploratory test] A link to a page using the a element with a charset attribute will cause a page with no other encoding information to be rendered using the encoding specified in the charset attribute.
No encoding declaration A page with no encoding information in HTTP, BOM, XML declaration or meta element will be treated as UTF-8.

Snapshot, 2012-12-12

All user agents detected character encodings declared in the HTTP header.

For little- and big-endian UTF-16 BOMs, the BOM triggers correct encoding in all browsers.

In the absence of other character encoding declarations, the XML declaration was used by Opera, Safari and Chrome to detect the character encoding for HTML documents. This use for HTML is not specified.

The meta content attribute was used by all browsers to set the encoding.

The meta charset attribute was also recognized by all browsers.

If a charset attribute was added to an a element that pointed to an HTML file with no other encoding information, no browser rendered the target page with the specified encoding. (Opera used to.)

All latest versions of browsers except Internet Explorer appear to use UTF-8 in the absence of encoding information.

Precedence

Assertion Gecko Presto Trident WebKit Detailed results
HTTP vs UTF-8 BOM A character encoding set in the HTTP header has lower precedence than the UTF-8 signature.
HTTP vs UTF-16LE BOM A character encoding set in the HTTP header has lower precedence than the UTF-16LE BOM.
HTTP vs UTF-16BE BOM A character encoding set in the HTTP header has lower precedence than the UTF-16BE BOM.
HTTP vs XML declaration [Exploratory test] The HTTP header has a higher precedence than an XML declaration.
HTTP vs meta content The HTTP header has a higher precedence than an encoding declaration in a meta content attribute.
HTTP vs meta charset The HTTP header has a higher precedence than an encoding declaration in a meta charset attribute.
UTF-8 BOM vs meta content A page with a UTF-8 BOM will be recognized as UTF-8 even if the meta content attribute declares a different encoding.
UTF-8 BOM vs meta charset A page with a UTF-8 BOM will be recognized as UTF-8 even if the meta charset attribute declares a different encoding.
XML declaration vs meta content [Exploratory test] The XML declaration has a lower precedence than an encoding declaration in a meta content attribute.
XML declaration vs meta charset [Exploratory test] The XML declaration has a lower precedence than an encoding declaration in a meta charset attribute.
meta content, then meta charset An encoding declaration in a meta content attribute has a higher precedence than a following encoding declaration in a meta charset attribute.
meta charset, then meta content An encoding declaration in a meta charset attribute has a higher precedence than a following encoding declaration in a meta charset attribute.

Snapshot summary, 2012-12-12

The BOM overrides the HTTP character encoding declaration for all browsers except Firefox and Internet Explorer 10.

A byte-order mark overrides all in-document declarations in all browsers tested.

Although some browsers use the XML declaration to set the encoding in the absence of other information (see the previous table), no browser uses that information in preference to a meta element. (Note that use of the XML declaration is not described in the HTML spec.)

When both a meta content attribute and meta charset attribute appear in an HTML page, the first always trumps the second.