If you’ve mastered HTML, you’re 90% of the way towards using XHTML. They’re actually very much the same thing—tag-based markup languages used to display Web pages. The difference is only seen by the people creating the pages (Web designers, programmers, etc.) and focuses on “forgivability”— HTML allows for some ugly code (mixed-case tags like <BoDy>, improperly nested elements, and unclosed tags), while XHTML does not. If you write HTML, it’s probably a good idea to start using XHTML practices anyway. It will take 5 minutes to learn, and it’s just a better way of doing things.
This is simple enough. Instead of using tags like <P>, <STRONG>, and <TABLE>, use <p>, <strong>, and <table>. Look at that! You’re 1/3rd of the way towards being an XHTML guru.
Again, something a good Web designer does anyway. But if you’re one the few people who still leaves <p> tags unclosed, now’s the time to start closing them.
Example of valid HTML:
<p>This is a paragraph
Equivalent in XHTML:
<p>This is a paragraph</p>
Tags that don’t contain data (like breaks, images, and horizontal rules) should also be closed in HTML. There’s no need to write an opening and closing tag, though. We can use the perfectly acceptable shortcut:
<!— Examples of properly closed XHTML tags -->
<!—Properly closed image -->
<img src=”someimage.gif” alt="An image" />
<!—Properly closed break tag -->
<br />
<!—Properly closed horizontal rule -->
<hr />
Here’s another area where good HTML coders are properly writing valid XHTML, even if they’re not aware. In HTML, the following code might display exactly as you intended:
<strong><em>Here’s some bold and italicized text</strong></em>
Although this might work, it’s not “good” code. And for the purposes of this article, not valid XHTML either. To complete your XHTML training, simply make sure your tags are properly nested:
<strong><em>Here’s a valid XHTML version of bold italicized code</em></strong>
XHTML is just cleaner HTML—tags are consistently lowercase, all tags are closed, and tags are properly nested. Making your pages valid XHTML is a piece of cake. And if you’ve been writing valid XHTML all along and never realized it, kudos! You can brag to your friends about how their old-school HTML pages are simply not up to par (Editors note: If you could really brag to your friends about this without them looking at you funny, I ask that you get up and attend a social event immediately. Conversations like this, even if you’re an IT professional, should be kept to a minimum. It scares other people and embarrasses your nerd friends who are trying to fit in.).
You must be logged in to post a comment.




