XHTML 1.1 Tutorial

XHTML Syntax

Even though most structures of the XHTML are similar to HTML, XHTML still requires some additional syntax rules to make it cleans. The significant syntax are concluded as in the table below:

 

Rule Description Example
Attribute Names Must Be In Lower Case As mention ealier that XHTML is case-sensitive. All attibute name must be in lower case. Where as the attribute values can be either upper or lower case. In HTML, we can use :
<a HREF="www.pitt.edu">This is link to Pitt</a>
In XHTML, it must be :
<a href="www.pitt.edu">This is link to Pitt</a>

Attribute Values Must Be Quoted HTML does not require that a value assigned to an attribute be enclosed in quotes. However, XHTML is very strict about this. If you forget to enclose in quotes, then XHTML will completely ignore the attribute. For example, in HTML we can use :
<table border=0 cellpadding=5>
In XHTML, it must be :
<table border="0" cellpadding="5">
No attribute may be minimized Having an attribute that does not have a value assigned to it is illegal in XHTML. In other words, no attribute minimization. For example, in HTML we can use :
<frame noresize />
In XHTML, it must be :
<frame noresize="noresize" />
"name" attribute is replaced by "id" attribute To assign the name properties with any elements, the attribute "id" replaces "name". However, to avoid the incompatible for old browser, you can add the attribute "name" if needed. For example, in HTML we can use :
<img src="img.gif" name="pic1">
In XHTML, it must be :
<img src="img.gif" id="pic1" />
The XHTML mandatory elements As we known that, like HTML, XHTML is a subset of the SGML. SGML use DTDs to define the context of the language. All XHTML documents must have a DOCTYPE declaration at the top (on the first line) of all XHTML code. The html, head and body elements must be present, and the title must be present inside the head element. This is the example of the XHTML mandatory elements :
<!DOCTYPE ....>
  <html>
  <head>
  <title>This is Title</title>
  </head>
  <body>This is body</body>
  </html>
The lang Attribute
The lang attribute is used to define the base language to be used for displaying text and characters on a Website. The languages are designated by a two letter code, such as "en" for English or "el" for Greek. For U.S. English, we can assign as "en-us".
This is the example of language attribute :
<html xmlns="http://www.w3.org/1999/xhtml" 
xml:lang="en" lang="en">

 

 



Previous Next

This tutorial is final project for INFSCI 2000, Fall 2004
Copyright 2004 School of Information Science, University of Pittsburgh