XHTML is the traditional name for what is now formally called the XML syntax of HTML, as opposed to the more commonly used HTML syntax, both of which are defined by the HTML5 standard. It is a markup language commonly used for HTML pages which are generated using a XML based tool chain. Do NOT use this tag for Facelets. Use [facelets] instead.
XHTML (eXtensible HyperText Markup Language) is an application of XML and a syntax of HTML. This syntax is available as an alternative to the more common HTML syntax, which was formerly based on SGML. It is a markup language commonly used for HTML pages which are used within an XML based tool as part of server-side specific (MVC) framework, such as Facelets and ASP.NET Web Forms.
Initially, XHTML 1.0 and XHTML 1.1 were defined in separate specifications from HTML 4.01, but now the HTML5 specification covers both syntaxes together.
The XML syntax has an orthogonal rule set which takes no account of the element types being used, whereas the HTML syntax has different rules for different types of elements. For example, void elements in HTML such as <link>
, <meta>
, <br>
and <hr>
are marked up using only start tags in the HTML syntax, while <div>
, <span>
, <a>
etc. must always have separate start and end tags. Other tags, for example <p>
, <li>
<td>
etc. have special rules about when start and end tags need to be used. In contrast, in the XHTML syntax all elements must be closed, either using separate start and end tags: e.g. <div>
and </div>
or, if they have no content, by using a shortened form e.g. <div />
The two syntaxes are mutually incompatible, and XML tools do not work directly on documents written in the HTML syntax.
XHTML was introduced to allow developers to exploit the simplification that this orthogonality brings.
XHTML is often used as the basis for server-side markup languages, so that the can be manipulated by XML-based tools. The final output of these tool chain might be generated documents in the regular HTML syntax or in the XHTML syntax prior to sending to the browser.
One common confusion with XHTML is over the use of doctypes and content types. Using one of the XHTML 1 doctypes (now all obsolete) caused HTML validators to check whether document were consistent with the XHTML syntax, while browsers treated the same documents as being in the regular HTML syntax. Browsers do not use the doctype to determine which syntax the document is in. Instead they use an HTTP header: content-type
. An XHTML syntax document must be supplied to the browser with an XML content type, usually application/xhtml+xml
or application/xml
. Regular HTML syntax documents should be supplied with a content type of text/html
. Modern validators now, like browsers, use the content type HTTP header to determine which syntax to check against, and for both syntaxes the doctype in the form <!DOCTYPE html>
should be used.
The XML syntax of HTML requires the following which are optional in the regular HTML syntax:
- Root XML namespace attribute as in
<html xmlns="http://www.w3.org/1999/xhtml">
- Elements must be nested. e.g.
<b><i></b></i>
is an error that will cause parsing to stop - Start and end Tags must always be matched, or elements self-closed. (e.g. use
<input></input>
or<input />
but not<input>
) - Tag and attribute names must be all in lowercase (e.g. use 'onclick
, not
onClick`) - Attribute values must be quoted with matching single or double quotes (e.g use
class='foo'
, orclass="foo"
, notclass=foo
) - Attribute minimization is forbidden (e.g. use
disabled="disabled"
ordisabled=""
, notdisabled
)