XHTML

Unit 4: New Web Technologies: XML, XHTML, CSS

Lesson 2: XHTML

Reference: XHTML: The Clean Code Solution by Peter Wiggin

What is XHTML?

Why use XHTML?

Differences between XHTML and HTML documents

Lowercase

All HTML tags and attribute names must be in lowercase

HTML:

      <BODY BGCOLOR="#ffffff">

XHTML:

      <body bgcolor="#ffffff">

Quoted Attribute Values

All attribute values must be quoted

HTML:

      <table border=0>...

XHTML:

      <table border="0">...

Terminate all tags

All tags, including non-empty elements must be terminated

HTML:

      Paragraph 1<p>
      Paragraph 2<p>

XHTML:

      <p>Paragraph 1</p>
      <p>Paragraph 2</p>

Properly Nested Tags

Elements must nest, not overlap

HTML:

      <p>here is a bolded <b>word.</p></b>

XHTML:

      <p>here is a bolded <b>word.</b></p>

Required elements

These should be in HTML anyway but are required in XHTML

What's New?

Doctype Declaration

For example:

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD 
        HTML 4.0 Transitional//EN">

Three different DTDs for XHTML 1.0

Strict

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">

Transitional

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">

Frameset

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/frameset.dtd">

Validating XHTML

<html> tag

      <html xmlns="http://www/w3/org/TR/xhtml1">

Processing Instructions

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

Empty elements must be terminated

HTML:

      <br>
      <hr>
      <img src="image.gif">

XHTML:

      <br />
      <hr />
      <img src="image.gif" />

Attribute value pairs cannot be minimized

HTML:

      <input type="radio" checked>
      <input type="checkbox" checked>
      <dl compact>

XHTML:

      <input type="radio" checked="checked" />
      <input type="checkbox" checked="checked" />
      <dl compact="compact">

Converting HTML to XHTML