1. What is XHTML?

Firstly, XHTML is among the family of the markup types, which are XML based. It is widely adopted by the developer community and is the most authentic form of HTML in use. Also, it is just like the reflection and extension of the HTML markup language. In general, XHTML can be defined as:

  • XHTML is the abbreviation of Extensible Hyper Text Markup Language
  • All major browsers support XHTML
  • XHTML can be defined as XHTML application
  • Rules are strict in XHTML and more like XML
  • An XHTML document can be viewed, edited, and validated with an XML tool
  • Unlike HTML4, XHTML documents perform and operate well with user agents
  • XTML document can incorporate applications like scripts and applets based on HTML DOM or XML DOM
Version Name Release Date
Developed By W3C
Initial Release 2000
Latest Release 2014
Extended From XML, HTML
Type Markup Language
File Extension .xhtml, .xht, .xml,
.html, .htm

Tutorial Contents:

  1. Introduction to XHTML
  2. HTML XHTML Differences
  3. Need for XHTML
  4. Validity Requirements
  5. Versions of XHTML

2. Differences Between HTML and XHTML

Importantly, to write some XHTML markup, there are certain rules to follow. These rules set the base of the XHTML. Also, this set of rules makes a difference between HTML and XHTML. The major differences between XHTML from HTML are listed below:

  • An XHTML document requires <!Doctype> as a must in the document
  • An important attribute in <html> tag is xmlns to make the document validated
  • The outmost HTML elements in a document are must which includes <html>, <head>, <title>and <body>
  • Nesting of Elements is required properly in XHTML
  • Elements in XHTML must be closed at the required and proper place
  • Lower case elements are needed in XHTML
  • Also, the name of attributes must also be in lower case
  • Further, the values of attributes must be in quotes
  • Minimized attributes are not allowed in XHTML

Note:

The xmlns attribute is must in XHTML, not valid in HTML 4.01 and not necessary in HTML5.
Syntax of xmlns Attribute
<html xmlns=”http://www.w3.org/1999/xhtml”>

3. What is the Need For XHTML?

Since XHTML is among the family of XML markup, where developers are able to create new elements as per requirements. However, this functionality is not available in XHTML and a developer is limited to only provided HTML elements. Also, a browser will always display the output of HTML markup, although there might be errors in the document.
Hence, the XHTML markup made HTML more flexible and extended it to work with other formats of data like XML. Also, it restricted the markup and formulated some rules for developers to follow to avoid errors. Thus, error handling is nicely done in XHTML and is the main reason behind its creation.
Moreover, the new user agents will readily work with the HTML which follows the standard set of rules of XHTML. Therefore, the concept of XHMTL is broad and helps the developer community in different ways.

4. Requirement of Validity of an XHTML Document

3.1. <!DOCTYPE> is Must in XHTML

First of all, <!Doctype> declaration is necessary for a document in XHTML. Usually, a doctype declaration tag is a singleton tag and has no ending tag. Also, this doctype declaration element is the very first HTML element in a document. It has the below syntax.

<!DOCTYPE html>

4.2. The xml Name Space is Required in XHTML

Usually, an xml namespace or simply xmlns attribute goes in <html> tag. It is a must requirement of an XHTML document. It has the below format.

<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
Cotent of document goes here
</html>

4.3. The Mandatory Elements For XHTML

Importantly, an XHTML document must have the <html>, <head>, <title>, and <body> elements. Othervise, the document will not be validated with XHTML.

Example

<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>The Title</title>
</head>
<body>

The Body Content..

</body>
</html>

4.4. Appropriate Nesting of XHTML Elements is Must

Furthermore, an XHTML document requires proper nesting of elements just like the below example.

Correct Nesting

<div><strong>XHTML Docuemnt</strong></div>

InCorrect Nesting

<div><strong>XHTML Docuemnt</div></strong>

4.5. XHTML Tags Must Always Be Closed

Moving further, an XHTML document has a rule that the element tags must be closed always.

Correct Closing of Tags

<h3>Thi is an XHTML heading</h3>
<p>A paragraph according to XHTML rules.</p>

InCorrect Closing of Tags

<h3>Thi is not an XHTML heading
<p>A paragraph not according to XHTML rules as it has no closing tag.

4.6. Empty Element in XHTML Must Be Closed

Just like other tags, the empty HTML elements need to be strictly closed. The only difference is that the empty elements are self-closing.

Correct Closing of Tags

Line Break Empty Element<br />
The horizontal line tag<hr />
The form element input tag<input type=”checkbox”/>

InCorrect Closing of Tags

Line Break Empty Element<br>
The horizontal line tag<hr>
The form element input tag<input type =”button”>

4.7. XHTML Elements Must be in Lower Case

The next rule of XHTML is that the element names must be in lower case. Although, writing the element’s name in the capital case will produce the correct results, but it is the XHTML requirement to write in lower case.
Similarly, the names of the attributes must also be written in lower case.

Correct Case

<div class=”firstDiv”>
<a href=”https:/www.tutsinsider.com”>Tuts Insider</a>
</div>

InCorrect Case

<DIV CLASS=”firstDiv”>
<A HREF=”https:/www.tutsinsider.com”>Tuts Insider</A>
</DIV>

4.9. Attributes Values Must be Quoted

Moreover, an XHTML document requires you to put attribute values within the quotes.

Correct

<a href=”https:/www.tutsinsider.com”>Tuts Insider</a>

InCorrect

<a href=https:/www.tutsinsider.com>Tuts Insider</a>

4.10. Attributes Minimization is Wrong in XHTML

An XHTML document does not allow attributes minimization. See the below instance:

Correct

<input type=”radio” name=”city” value=”Sydney” /a>
<input type=”radio” name=”city” value=”New York” checked=”checked” /a>

InCorrect

<input type=”radio” name=”city” value=”Rio” /a>
<input type=”radio” name=”city” value=”Paris” checked /a>

4.11. How to Validate an HTML Document?

Luckily, w3c provides a tool to validate the HTML or XHTML documents.
Write down the address of your HTML document in below field:


5. What are Different Versions of XHTML?

W3C released different versions of XHTML which are listed below:

Version Name Release Date
XHTML 1.0 January 26, 2000
XHTML 1.1 May, 2001
XHTML 1.2 Did not Release
XHTML 2.0 August 2002 – July 2006
XHTML 5.0 October, 2014
Give Us Your Feedback
OR
If You Need Any Help!
Contact Us