XHTML - EXtensible HyperText Markup Language

XHTML stands for EXtensible HyperText Markup Language. It is a markup language based on XML and almost identical to HTML. XHTML is stricter than HTML and does not allow any lapses in the code of webpages. XHTML is supported by all major browsers.

XHTML retains all the features of HTML, but introduced more strict rules for creating pages, which allows you to make sites independent of the display device and browser. This means that the site will be correctly displayed in all modern browsers and platforms like computers, smartphones, PDAs, etc.

XHTML is supported by all modern browsers.

Difference between HTML and XHTML

When writing XHTML code, we use HTML-specific syntax. The difference between HTML and XHTML is a set of some obligatory rules.

Document structure

  • Declaration of a document type (DTD) <!DOCTYPE> is required.
  • Presence of the xmlns attribute (points to the xml namespace) is required.
  • The <html>, <head>, <body> tags are required.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    Content of the page
  </body>
</html>

Result

XHTML Elements

  • The correct nesting of tags

XHTML is critical for the incorrect nesting of one tag into another and the location of the tag in a non-relevant container. For example, there is an error in the markup of the text <p> Lorem <b><i> ipsum dolor sit </b></i> amet </p>, the tag </b> must be located after the tag </i>, and not precede it.

  • All tags must be closed.

Unlike HTML, where we can sometimes omit the closing tag, in XHTML the closing tag is required always and everywhere.

<br /> - break
<hr /> - horizontal line
<img src="image.jpg"/> - image

  • All tags must be typed in lowercase.

Lowercase and uppercase tags are distinguished in XHTML. To avoid confusion, all tags, as well as their attributes must be typed in lowercase.

  • In a XHTML document there must be at least one root element.

XHTML attributes

  • All attributes must be typed in lowercase.
  • Values of all attributes must be quoted.

We have this rule in HTML too, but however, the absence of quotes doesn’t affect the correctness of the code, and in XHTML quoting attributes values is necessary.

<table width="200" border="1" cellpadding="5" cellspacing="0">

  • Using abbreviated tag attributes isn’t permitted.

Abbreviated attribute is not assigned a value. An attribute can be assigned an attribute value that matches the name. For example, instead of checked (HTML), used is checked = "checked" (XHTML).

  • Instead the name attribute you’ve better use id.

In XHTML the name is partially obsolete, that’s why it’s recommended to use id attribute.