What is XHTML?

Understand XHTML and create simple XHTML file.


Share on Google+Share on Google+

What is XHTML?


Understand XHTML and create simple XHTML file.

What is XHTML

XHTML (eXtensible HyperText Markup Language) is extended, stricter and cleaner version of HTML 4 and is designed to work with XML.

Rules for creating XHTML document

In html, if you omit an end-tag or leave a quote etc, the page still displays its content and nothing too serious happens with the page. But as XHTML is a combination of html and xml, writing code is much harder and stricter than html but it makes the code cleaner and more self explanatory. XHTML document should follow some rules as given below:

  1. Tags and attributes names must be in lowercase
  2. "Empty" tags must be properly ended with closing slash
  3. Tags with opening tag must have an end tag
  4. Attributes must always have a value
  5. Attributes values must be quoted
  6. Must have a DOCTYPE declaration.
  7. html, head, title, and body elements must be present.

Valid XHTML documents:

  1. The XHTML document must have html as root element, and must contain an xmlns attribute to link it with the XHTML namespace.

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

  2. A Document Type Declaration, or DOCTYPE, may be used to validate an XHTML document.
  3. XHTML document may have XML declaration at the beginning.

    <?xml version="1.0" encoding="UTF-8"?>


  1. The code is cleaner and more self-explanatory.
  2.  Web browsers are able to parse, process and display the page more easily than one with errors and unformatted code.
  3. Easy to maintain, edit, convert and format the code.
  4. Render more correctly in more browsers because of following W3C standard rules.
  5. Increased interoperability
  6. Greater accessibility

Sample XHTML document: 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title> Sample XHTML</title>
<p>Sample XHTML</p>



Posted on: November 2, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles