Fast and Easy XHTML
10:32 AM - Dec 9, 2001
Wondering how to turn your HTML code into XHTML? Here are a few quick tips to teach you the very basics, a sample XHTML document, and resources for more information.
<br />
<hr />
(Below is an XHTML document sample that shows more of these.)
Notice that since the <img> tag doesn’t have a corresponding ending tag that it also is closed with the extra space and slash, too.
This is correct:
<p><strong>Text</strong></p>
<a href="http://www.foo.com/cgi-bin/class.pl?
saturday&night&live">foo</a>
must instead be:
<a href="http://www.foo.com/cgi-bin/class.pl?
saturday&night&live">foo</a>
In addition to the above is a new DTD, too. The sample below is for XHTML 1.0 transitional.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
The first line within the <? and ?> is recommended but not required. It tells the browser that your document is based upon a DTD using XML, and that it’s using a standard character encoding.
The second line with the <!DOCTYPE ....> will look more familiar to you, this time representing XHTML 1.0 transitional.
Then, the last line beginning with <html xmlns=" ....> replaces the <html> tag, telling the browser the language and the namespace.
Below is a sample XHTML document. Note that all the markup is in lowercase, there are quotes around the attribute values, the new endings for the tags that don’t have corresponding ending tags, and it is all well formed.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Nifty New XHTML document</title>
<meta name="description" content="This is the coolest XHTML document on the 'Net." />
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<p>Content here.</p>
<p>Content here.</p>
<ol>
<li>List item one</li>
<li>List item two</li>
</ol>
<dl>
<dt>Term
<dd>definition</dd>
</dt>
</dl>
<img src="image.gif" height="150" width="40" alt="funny face" />
<br />
<table width="200" border="1" cellspacing="0" cellpadding="5">
<tr><td>Green eggs</td><td>Ham</td></tr>
</table>
<form method="get" action="foo">
<select name="">
<option value="all">All Products</option>
<option value="books">Books</option>
</select>
<input type="text" name="keyword" size="10"
value="" />
<input type="submit" name="Search" value="Go!" />
</form>
</body>
</html>
Ready to give it a try? If you already know HTML, I suspect you can learn how to implement these markup changes within a couple of hours. If you just dig in and try it, I think you’ll be pleasantly surprised to see that it’s easier than you may have thought.
To learn lots more about XHTML, check out WebsiteTips.com’s XHTML section for annotated links to W3C recommendations, articles and tips, sites devoted to XHTML, and more.
Also highly recommended is Molly Holzschlag’s book, XML, HTML, XHTML Magic published by New Riders.
These tips have also been added to WebsiteTips.com’s Tutorials - XHTML Tutorials: Fast and Easy XHTML and includes a downloadable PDF version, too.]
[Home: Mobile · Main]