Identifying media type and character encoding
It is recommended (although not required) that the media type and character encoding be specified within (X)HTML documents as a way to keep that information with the document. (For more information on declaring character encodings, see Chapter 6.)
This is done using the meta
element, as shown in this example:
<metahttp-equiv="content-type"
content="text/html; charset=UTF-8"
/>
The parts are broken down as follows:
- Media type identification
The media type, very similar to MIME types used for sending email attachments, is another bit of information sent in the HTTP header. For HTML documents, the media type is always
text/html
. That one is easy. XHTML documents, on the other hand, are not as straightforward.XHTML 1.0 documents may be served as either XML or HTML documents. Although XML is the proper method, due to lack of browser support for XML files, many authors choose to deliver XHTML 1.0 files with the
text/html
MIME type used for HTML documents. When XHTML documents are served in this manner, they may not be parsed as XML documents.XHTML 1.0 files may also be served as XML using the MIME types
application/xhtml+xml
,application/xml
, ortext/xml
. The W3C recommends that you useapplication/xhtml+xml
only.XHTML 1.1 documents are not permitted to use the
text/html
media type. This poses a problem because some browsers do not know what to do with the non-text/html
media types. This is another reason why XHTML 1.1 is still difficult to ...
Get Web Design in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.