Tuesday, 11 November 2008

XHTML - A very simple primer.

XHTML is a reformulation of HTML in XML. XML is mainly made up of generic tags which can be used to define data. XHTML is derived from XML or putting it the other way, XML is the base for XHTML. XHTML is also very similar to HTML 4.1.

According to W3Schools,

“XHTML is a combination of HTML and XML (EXtensible Markup Language). XHTML consists of all the elements in HTML 4.01, combined with the strict syntax of XML.”

Tips to be XHTML 1.0 compliant

1. Start writing your tags and attribute names in lower cases

for eg. <BODY> - is wrong

<body> -  is correct.

<table WIDTH = “100%”> – is wrong

<table width = “100%” > – is correct

2. Always close your tags.

for eg. <p> this is a paragraph – is wrong

<p> this is a paragraph </p> – is correct

Be particularly aware when using tags like <img> <br> which do have a self closing tag in HTML 4.0,

These need to have a self-closing tag which is described as below.

<img src=”c:\\images\\alive.png”> – is wrong

<img src=”c:\\images\\alive.png” /> – is correct.

<br> – is wrong

<br/> – is correct

3. Nest your tags correctly

      <li>Black tea</li>
      <li>Green tea</li>

- is wrong


      <li>Black tea</li>
      <li>Green tea</li>

- is correct

4. XHTML documents MUST have a root element - <html>

The document structure should look like

<head> ... </head>
<body> ... </body>

5. Attribute values MUST be in quotes

<div id=header >

</div> – is wrong

<div id=”header”>

</div> – is correct

<table width=”100%”> - is correct.

<table width=100%> -  is wrong.

6. Always add a  <!DOCTYPE> declaration to you page.

A DOCTYPE gives the browser information about the kind of HTML it expects.

The DOCTYPE declaration is always the first line in an XHTML document.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<title> xhtml document</title>
<p> welcome to xhtml standards</p>


The XHTML DTD (Document type definition) defines the syntax of the XHTML markup.


XHTML 1.0 Strict


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"


XHTML 1.0 Transitional


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

Use the transitional DOCTYPE for valid markup and pages which render the same in all major browsers.


XHTML 1.0 Frameset

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"

Use the frameset DOCTYPE when you want to use HTML frames.


How w3schools was converted to xhtml


Useful Links

The XHTML 1.0 markup language (Second Edition) - http://www.w3.org/TR/xhtml1/ 

The XHTML Validator -  http://validator.w3.org/

W3School’s XHTML Tutorial -  http://www.w3schools.com/xhtml/

No comments:

Post a Comment