Advertisement
❮ Previous: HTML Url Encoding Next: HTML Forms ❯

HTML vs XHTML

XHTML

XHTML stands for EXtensible HyperText Markup Language.

The XHTML 1.0 is the first document type in the XHTML family.

XHTML is almost identical to HTML 4.01 with only few differences. This is a cleaner and stricter version of HTML 4.01.

XHTML was developed by World Wide Web Consortium (W3C) to help web developers make the transition from HTML to XML. By migrating to XHTML today, web developers can enter the XML world with all of its benefits, while still remaining confident in the backward and future compatibility of the content.


What is HTML?

This is Standard Generalized Markup Language (SGML) application conforming to International Standard ISO 8879. HTML is widely regarded as the standard publishing language of the World Wide Web.


What is SGML?

This is a language for describing markup languages, particularly those used in electronic document exchange, document management, and document publishing. HTML is an example of a language defined in SGML.


What is XML?

XML stands for EXtensible Markup Language. XML is a markup language much like HTML and it was designed to describe data. XML tags are not predefined. You must define your own tags according to your needs.


Important Points to Remember

  1. Write a DOCTYPE declaration at the start of the XHTML document.
  2. Close all XHTML tags properly.
  3. Write all XHTML tags and attributes in lower case only.
  4. Forbid Attribute minimization.
  5. Nest all the tags properly.
  6. Quote all the attribute values.
  7. Nest all the tags properly.
  8. Replace the name attribute with the id attribute.

DOCTYPE Declaration

XHTML Is Mandatory

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Case Sensitivity

XHTML is case sensitive markup language. All the XHTML tags and attributes need to be written in lower case only.

Wrong Practice

<A Href="https://www.example.com">Example</A>

Correct Practice

<a href="https://www.example.com">Example</a>

XHTML Empty Elements

In XHTML, empty elements must always be closed, like this:

Wrong Practice

A break: <br>
A horizontal rule: <hr>

Correct Practice

A break: <br />
A horizontal rule: <hr />

Advertisement

XHTML Elements Must be in Lowercase

In XHTML, element names must always be in lowercase, like this:

Wrong Practice

<P>Paragraph</P>

Correct Practice

<p>Paragraph</p>

XHTML Attribute Names Must be in Lowercase

Wrong Practice

<p CLASS="one">Paragraph</p>

Correct Practice

<p class="one">Paragraph</p>

XHTML Attribute Values Must be Quoted

Wrong Practice

<p class=one>Paragraph</p>

Correct Practice

<p class="one">Paragraph</p>

Attribute Minimization

XHTML does not allow attribute minimization. It means you need to explicitly state the attribute and its value.

Wrong Practice

<input disabled />

Correct Practice

<input disabled="disabled" />

Here is a list of the minimized attributes in HTML and the way you need to write them in XHTML

HTML XHTML
compact compact="compact"
checked checked="checked"
declare declare="declare"
readonly readonly="readonly"
disabled disabled="disabled"
selected selected="selected"
defer defer="defer"
ismap ismap="ismap"
nohref nohref="nohref"
noshade noshade="noshade"
nowrap nowrap="nowrap"
multiple multiple="multiple"
noresize noresize="noresize"

Closing the Tags

Each and every XHTML tag should have an equivalent closing tag, even empty elements should also have closing tags.

Wrong Practice

<p>Paragraph

Correct Practice

<p>Paragraph</p>
❮ Previous: HTML Url Encoding Next: HTML Forms ❯
Advertisement