How to create a valid XHTML webpage
1. (Optional) Use an xml prologue:
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
(be aware that doing so will force Internet Explorer into Quirks Mode. Don't know what that means? Go to Google. There are thousands of articles detailing the whys and wherefores. My advice? Skip it. It's not necessary.)
2. Use a proper,
valid DOCTYPE:
XHTML 1.0 Strict, Transitional, Frameset
Code:
<!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 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
XHTML 1.1 DTD
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3. a) (If you use XHTML 1.0) Change your <html> tag to read:
Code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3. b) (If you use XHTML 1.1) Change your <html> tag to read:
Code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4. Include this in amongst your usual <meta> tags in the <head>:
Code:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
5. Remember to
close all your tags!! This means when you open a <p>, close it with </p>.
6. Validate your pages against
http://validator.w3.org.
And that's it!
Of course, this is only the beginning. By taking this first step you are opening yourself up to the wonderful world of designing with web standards, and can start to truly appreciate the amazing bandwidth savings you can achieve.
(Having said that it is perfectly possible to have a completely valid XHTML document that uses nested tables, spacer gifs and all the outdated junk markup HTML is littered with. But what would be the point of that, right?)
ps...To any XHTML purists out there, I know that if you use XHTML you should serve your document as application/xhtml+xml, but until there is a reliable way of doing this that doesn't give Internet Explorer the willies, I'll stick to the old-fashioned text/html. I know of one resource that may be of use, but haven't tried it. The url to the article is:
http://keystonewebsites.com/articles/mime_type.php. If someone's tried it and fancies sharing their knowledge, please do!
