XHTML

  • Revision slug: XHTML
  • Revision title: XHTML
  • Revision id: 330087
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment deplicated id

Revision Content

HTML can be transferred over the network to the browser using two syntaxes: HTML syntax and XML syntax, also known as XHTML.

HTML5 and HTML/XHTML

Both of these syntaxes are defined by the HTML5 standard. The choice of syntax is indicated by the MIME type, which is sent in the HTTP Content-Type header. The MIME type for HTML syntax is text/html, and the MIME type for XHTML syntax is aplication/xhtml+xml.

This example shows an HTML document and an XHTML document including the relevant HTTP headers.

HTML document

HTTP/1.1 200 OK
Content-Type: text/html

<!DOCTYPE html>
<html lang=en>
  <head>
    <meta charset=utf-8>
    <title>HTML</title>
  </head>
  <body>
    <p>I am a HTML document
  </body>
</html>

XHTML document

HTTP/1.1 200 OK
Content-Type: application/xhtml+xml

<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>XHTML</title>
  </head>
  <body>
    <p>I am a XHTML document</p>
  </body>
</html>

MIME type versus DOCTYPE

Prior to HTML5, the two syntaxes were defined by two separate specifications: HTML 4.01 and XHTML 1.0. The XHTML1 standard claimed that you could use XHTML by declaring a special DOCTYPE. This has however never been implemented by any browser, and has been changed in the HTML5 standard. If your page is sent as text/html, you are not using XHTML. Note that the MIME type must be located in the Content-Type HTTP header. If you only put it into an HTML meta tag like <meta http-equiv=…>, it will be ignored and treated like text/html.

If you serve your pages as text/html and believe that you are writing XHTML, you may face several problems, as described in the following articles:

Support

XHTML is supported by most modern browsers, including Firefox, Chrome, Safari, and Opera. Note, however, that Internet Explorer only supports XHTML starting with version 9. Internet Explorer 8 and older will instead show a download dialog box for unknown file types when it sees an XHTML document with the correct XHTML MIME type.

Also be aware that many popular JavaScript libraries and developer tools do not support or have limited support for XHTML.

Differences from HTML

See Properly Using CSS and JavaScript in XHTML Documents for a list of some of the differences between HTML and XHTML.

Tools

See also

View All...

{{ languages( { "fr": "fr/XHTML", "es": "es/XHTML", "it": "it/XHTML", "ja": "ja/XHTML", "pt": "pt/XHTML", "pl": "pl/XHTML" } ) }}

Revision Source

<p><a href="/en/HTML" title="HTML">HTML</a> can be transferred over the network to the browser using two syntaxes: HTML syntax and <a href="/en/XML" title="XML">XML</a> syntax, also known as XHTML.</p>
<h2 id="HTML5_and_HTML.2FXHTML">HTML5 and HTML/XHTML</h2>
<p>Both of these syntaxes are defined by the <a href="/en/HTML/HTML5" title="HTML5">HTML5</a> standard. The choice of syntax is indicated by the MIME type, which is sent in the HTTP <code>Content-Type</code> header. The MIME type for HTML syntax is <code>text/html</code>, and the MIME type for XHTML syntax is <code>aplication/xhtml+xml</code>.</p>
<p>This example shows an HTML document and an XHTML document including the relevant HTTP headers.</p>
<h3 id="HTML_document">HTML document</h3>
<pre class="brush: html">
HTTP/1.1 200 OK
Content-Type: text/html

&lt;!DOCTYPE html&gt;
&lt;html lang=en&gt;
  &lt;head&gt;
    &lt;meta charset=utf-8&gt;
    &lt;title&gt;HTML&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;I am a HTML document
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<h3 id="XHTML_document">XHTML document</h3>
<pre class="brush: xml">
HTTP/1.1 200 OK
Content-Type: application/xhtml+xml

&lt;html xml:lang="en" xmlns="<code>http://www.w3.org/1999/xhtml</code>"&gt;
  &lt;head&gt;
    &lt;title&gt;XHTML&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;I am a XHTML document&lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<h2 id="MIME_type_versus_DOCTYPE">MIME type versus DOCTYPE</h2>
<p>Prior to HTML5, the two syntaxes were defined by two separate specifications: <a class="external" href="http://www.w3.org/TR/html4/" title="http://www.w3.org/TR/html4/">HTML 4.01</a> and <a class="external" href="http://www.w3.org/TR/xhtml1/">XHTML 1.0</a>. The XHTML1 standard claimed that you could use XHTML by declaring a special DOCTYPE. This has however never been implemented by any browser, and has been changed in the HTML5 standard. <strong>If your page is sent as <code>text/html</code>, you are not using XHTML</strong>. Note that the MIME type must be located in the <code>Content-Type</code> HTTP header. If you only put it into an HTML meta tag like <code>&lt;meta http-equiv=…&gt;</code>, it will be ignored and treated like <code>text/html</code>.</p>
<p>If you serve your pages as <code>text/html</code> and believe that you are writing XHTML, you may face several problems, as described in the following articles:</p>
<ul>
  <li><a class="external" href="http://www.spartanicus.utvinternet.ie/no-xhtml.htm">No to XHTML</a> an excellent article from Spartanicus</li>
  <li><a class="external" href="http://www.webdevout.net/articles/beware-of-xhtml">Beware of XHTML</a> by David Hammond</li>
  <li><a class="external" href="http://www.hixie.ch/advocacy/xhtml">Sending XHTML as text/html Considered Harmful</a> by Ian Hickson</li>
  <li><a class="external" href="http://www.xml.com/pub/a/2003/03/19/dive-into-xml.html">XHTML's Dirty Little Secret</a> by Mark Pilgrim</li>
  <li><a class="external" href="http://hsivonen.iki.fi/xhtml-the-point/">XHTML - What's the Point?</a> by Henri Sivonen</li>
  <li><a class="external" href="http://lachy.id.au/log/2005/12/xhtml-beginners">XHTML is not for Beginners</a> by Lachlan Hunt</li>
</ul>


<h2>Support</h2>
<p>XHTML is supported by most modern browsers, including Firefox, Chrome, Safari, and Opera. Note, however, that Internet Explorer only supports XHTML starting with version 9. Internet Explorer 8 and older will instead show a download dialog box for unknown file types when it sees an XHTML document with the correct XHTML MIME type.</p>
<p>Also be aware that many popular JavaScript libraries and developer tools do not support or have limited support for XHTML.</p>


<h2>Differences from HTML</h2>
<p>See <a href="/en/Properly_Using_CSS_and_JavaScript_in_XHTML_Documents" title="Properly Using CSS and JavaScript in XHTML Documents">Properly Using CSS and JavaScript in XHTML Documents</a> for a list of some of the differences between HTML and XHTML.</p>


<h2 id="Tools" name="Tools">Tools</h2>
<ul>
  <li><a href="/en/Standards-Compliant_Authoring_Tools" title="en/Standards-Compliant_Authoring_Tools">Standards-Compliant Authoring Tools</a></li>
</ul>
<h2 id="See_also">See also</h2>
<ul>
  <li><a href="/en/HTML" title="en/HTML">HTML</a></li>
  <li><a href="/en/Namespaces" title="en/Namespaces">Namespaces</a></li>
</ul>
<p><span class="alllinks"><a href="/Special:Tags?tag=XHTML:Tools&amp;language=en" title="Special:Tags?tag=XHTML:Tools&amp;language=en">View All...</a></span></p>
<p>{{ languages( { "fr": "fr/XHTML", "es": "es/XHTML", "it": "it/XHTML", "ja": "ja/XHTML", "pt": "pt/XHTML", "pl": "pl/XHTML" } ) }}</p>
Revert to this revision