XHTML - Intro to XHTML

  »   XHTML  »   XHTML Tutorial - XHTML intro

If you have some basic knowledge about HTML, you will see that XHTML is the logical next step to it. XHTML is not a programming language, but a markup one, just like HTML. It stands for eXtensible HyperText Markup Language, and it is a strict and cleaner version of HTML. It is sometimes considered a combination between HTML andXML.

XHTML 1.0 become a recommendation of W3C (World Wide Web Consortium) on 26 January 2000. XHTML it is now a standard and it is fully compatible with all browsers.

HTML and XHTML differences

As I mention above XHTML it's a strict version of HTML. We will take next example to demonstrate this affirmation. For example many browsers will display the next code with no errors.

 <title>This the wrong place to put the title</title>
 <h1>Heading here
 <p>And a simple paragraph

This well be a valid HTML code, but invalid as XHTML Here are some things to bear in mind about XHTML. XHTML tags must: p>

  • always be closed
  • always be closed in the same order they were open
  • always be lowercase
  • always be opened in a specific order

Let's continue with some examples about each case.

1. In XHTML all elements must be closed

Accepted HTML code

HTML<p>This is a simple paragraph
<p>This is another paragraph

Valid XHTML code

XHTML<p>This is a simple paragraph</p>
<p>This is another paragraph</p>

A very often mistake is not to close the list tags

 <li>Element 1
 <li>Element 2

Valid XHTML code

 <li>Element 1</li>
 <li>Element 2</li>

2. In XHTML all elements must be closed in the same order they were opened

Accepted HTML code

HTML<b><i>This is a bold and italic paragraph</b></i>

Valid XHTML code

XHTML<b><i>This is a bold and italic paragraph</i></b>

3. In XHTML all elements must be lowercase.

Accepted HTML code

 <TITLE>Invalid XHTML code</TITLE>
 <P>A simple paragraph</P>

Valid XHTML code

 <title>Invalid XHTML code</title>
 <p>A simple paragraph</p>

4. All XHTML elements must be opened and closed in the proper and specific order.

Here we refer to a specific document structure. To the fact that all XHTML elements must be encapsulated in the html tag. The html tag needs to have a head and a body tag and all other tags must be opened and closed in the proper order.

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