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.

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

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
  • ul>

    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

    HTML<ul>
     <li>Element 1
     <li>Element 2
    ul>

    Valid XHTML code

    XHTML<ul>
     <li>Element 1</li>
     <li>Element 2</li>
    ul>

    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

    HTML<HTML>
     <HEAD>
     <TITLE>Invalid XHTML code</TITLE>
     HEAD>
     <BODY>
     <P>A simple paragraph</P>
     </BODY>
    </HTML>

    Valid XHTML code

    XHTML<html>
     <head>
     <title>Invalid XHTML code</title>
     </head>
     <body>
     <p>A simple paragraph</p>
     </body>
    </html>

    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.

    XHTML<html> 
     <head>.... </head>
     <body>.... </body>
    </html>