Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 739135 of XHTML

  • Revision slug: Glossary/XHTML
  • Revision title: XHTML
  • Revision id: 739135
  • Created:
  • Creator: Andrew_Pfeiffer
  • Is current revision? No
  • Comment

Revision Content

HTML can travel over the network to a browser either in HTML syntax or XML syntax, also known as XHTML.

HTML5 and HTML/XHTML

The HTML5 standard defines both these syntaxes. 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 application/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</p>
  </body>
</html>

XHTML document

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

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

MIME type versus DOCTYPE

Before HTML5, the two syntaxes were defined by two separate specifications: HTML 4.01 and XHTML 1.0. According to the XHTML1 standard,  you could use XHTML by declaring a special DOCTYPE. However, no browsers have ever implemented this, and the HTML5 standard has reversed the decision. If your page is sent as text/html, you are not using XHTML.

Instead, the proper MIME type must be present in the Content-Type HTTP header. If you only put the MIME type 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 these articles:

Support

Most modern browsers support XHTML, including Firefox, Chrome, Safari, Opera, and Internet Explorer (since IE 9). (Internet Explorer 8 and older browsers instead show a download dialog box for unknown file types when they see an XHTML document with the correct XHTML MIME type.)

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

Differences from HTML

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

Tools

See also

View All...

Revision Source

<p><a href="/en-US/docs/HTML" title="HTML">HTML</a> can travel over the network to a browser either in HTML syntax or <a href="/en-US/docs/XML" title="XML">XML</a> syntax, also known as XHTML.</p>

<h2 id="HTML5_and_HTML.2FXHTML">HTML5 and HTML/XHTML</h2>

<p>The <a href="/en-US/docs/HTML/HTML5" title="HTML5">HTML5</a> standard defines both these syntaxes. 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>application/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;/p&gt;
  &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>https://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>Before HTML5, the two syntaxes were defined by two separate specifications: <a class="external" href="https://www.w3.org/TR/html4/" title="https://www.w3.org/TR/html4/">HTML 4.01</a> and <a class="external" href="https://www.w3.org/TR/xhtml1/">XHTML 1.0</a>. According to the XHTML1 standard,&nbsp; you could use XHTML by declaring a special DOCTYPE. However, no browsers have ever implemented this, and the HTML5 standard has reversed the decision. <strong>If your page is sent as <code>text/html</code>, you are not using XHTML</strong>.</p>

<p>Instead, the proper MIME type must be present in the <code>Content-Type</code> HTTP header. If you only put the MIME type 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 these articles:</p>

<ul>
 <li><a class="external" href="https://www.spartanicus.utvinternet.ie/no-xhtml.htm">No to XHTML</a> an excellent article from Spartanicus</li>
 <li><a class="external" href="https://www.webdevout.net/articles/beware-of-xhtml">Beware of XHTML</a> by David Hammond</li>
 <li><a class="external" href="https://www.hixie.ch/advocacy/xhtml">Sending XHTML as text/html Considered Harmful</a> by Ian Hickson</li>
 <li><a class="external" href="https://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="https://hsivonen.iki.fi/xhtml-the-point/">XHTML - What's the Point?</a> by Henri Sivonen</li>
 <li><a class="external" href="https://lachy.id.au/log/2005/12/xhtml-beginners">XHTML is not for Beginners</a> by Lachlan Hunt</li>
</ul>

<h2 id="Support">Support</h2>

<p>Most modern browsers support XHTML, including Firefox, Chrome, Safari, Opera, and Internet Explorer (since IE 9). (Internet Explorer 8 and older browsers instead show a download dialog box for unknown file types when they see an XHTML document with the correct XHTML MIME type.)</p>

<p>Also be aware that many popular JavaScript libraries and developer tools have limited or no support for XHTML.</p>

<h2 id="Differences_from_HTML">Differences from HTML</h2>

<p>See <a href="/en-US/docs/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 partial list of differences between HTML and XHTML.</p>

<h2 id="Tools" name="Tools">Tools</h2>

<ul>
 <li><a href="/en-US/docs/Standards-Compliant_Authoring_Tools" title="Standards-Compliant_Authoring_Tools">Standards-Compliant Authoring Tools</a></li>
</ul>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/HTML" title="HTML">HTML</a></li>
 <li><a href="/en-US/docs/Namespaces" title="Namespaces">Namespaces</a></li>
</ul>

<p><span class="alllinks"><a href="/en-US/docs/tag/XHTML:Tools" title="tag/XHTML:Tools">View All...</a></span></p>
Revert to this revision