If you find this helpful, please click the Google |


Content-Type Header
And Other HTTP Headers for HTML
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 document is displayed might look like this:
Content-Type: application/xhtml+xml; charset=UTF-8 X-UA-Compatible: IE=9
For static web pages, the headers are provided by the HTTP web server.
When a server-side program or scripting is generating HTML, the language probably has an API to send the proper HTTP headers.
.htaccess Code for Content-Type Header
Set Content-Type Header using .htaccess AddType
For static web pages, it may be necessary to add the MIME Type for HTML 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):
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 HTML 5's HTML Serialization.
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.
HTTP Header Examples
Examples of HTTP Headers for HTML
DirectoryIndex index.html ErrorDocument 404 /error.html AddType application/xhtml+xml; charset=UTF-8 html
In this example, the DirectoryIndex
document comes from the directory indicated by the HTTP request URL and the ErrorDocument
comes from the document root directory, due to the leading slash (/
) in that directive. The Content-Type header for any .html documents will have a value of application/xhtml+xml
and the documents will be encoded with UTF-8 character encoding.