XHTML, A Better, Cleaner HTML
Category: HTMLReviewed by: Chiggins
Reviewed on: Dec 06 2007
» Discuss this topic (0 Posts)
Id Attribute replaces the name attribute
In HTML 4.01 the name attribute is defined in the a, applet, frame, iframe, img, and map tags. In XHTML, the name attribute is deprecated, and we use id.
This is wrong: <img src=thingy.gif name=thingy /> This is correct: <img src=thingy.gif id=thingy /> To compensate for older browsers, use both: <img src=thingy.gif id=thingy name=thingy />
The lang Attribute
Now in XHTML, the lang attribute is in almost every tag. It is used to show the language of the content of the tag. If we are to use the lang attribute, we must also use the xml:lang attribute.
<div lang=en xml:lang=en>Hello!</div> <div lang=es xml:lang=es>Hola!</div>
The DOCTYPE
The XHTML standard now defines three Document Type Definitions (DTD). They are Strict, Frameset, and the most common, Transitional. The DOCTYPE declaration must be at the start of every XHTML document, and because it is not a tag, it does not need an ending tag. Here is a minimal XHTML document with a Strict DTD.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Simple XHTML Page</title> </head> <body> <p>This is a simple, minimal XHTML page.</p> </body> </html>
To define each DTD, use each of these:
Strict DTD<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Frameset//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd>
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
Each DTD has its own used. Use Strict when you want very clean markup, free of clutter, and it works great with CSS. Transitional is used when you want to use of some deprecated HTML features, and browsers that dont understand CSS. Lastly, Frameset is used when you want to have a page that has frames to partition the browsers window.

