HTTP Headers for HTML 5

How to set the Content-Type Header for HTML

(Setting the parameters to send the proper HTTP headers from a web server requires a bit of technical know-how. You may want to skip directly to the Basic HTML Code section. You will want to come back later if your site shows a "torn page" (broken page) icon in the address bar of Internet Explorer so bookmark this page in your Favorites to find it easily.

HTTP headers are sent to the client (browser) in the response from the web server before the document itself. The HTTP headers which control how an HTML 5 document is displayed might look like this:

Content-Type: application/xhtml+xml; charset=UTF-8
Cache-Control: max-age=120
X-UA-Compatible: IE=9

It is highly recommended that the charset attribute specifying the character encoding of the HTML page be included in the Content-Type header for non-XML user agents as well as in the xml declaration for XML parsers.

For static web pages, it may be necessary to add the MIME Type for HTML 5 Polyglot Documents to the HTTP web server configuration to send the appropriate Content-Type header. With the Apache HTTP Server, for example, the HTML 5 MIME Type can be added to the .htaccess file(s):

DirectoryIndex index.html
ErrorDocument 404 /error.html
AddType application/xhtml+xml;charset=UTF-8 html

For a detailed explanation of why the Content-Type header is set to application/xhtml+xml, see the HTML Serialization section below.

When a program or server-side scripting is generating HTML, the language probably has an API to send the proper HTTP headers.