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/htmlMIME 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+xmlonly.XHTML 1.1 documents are not permitted to use the
text/htmlmedia type. This poses a problem because some browsers do not know what to do with the non-text/htmlmedia types. This is another reason why XHTML 1.1 is still difficult to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access