XHTML vs. HTML

January 3rd, 2009

For all intensive purposes, XHTML is a more strict version of HTML with some of the benefits of XML. It’s goal is to be more cross-browser compatible. With that said, many of the websites I author, I still author in HTML, even though I follow 95% of the XHTML rules. Really, changing to XHTML would be pretty easy for me, because the only rule I don’t follow is I don’t close my tags that aren’t a pair. For example, I don’t close my break tags.

HTML <br> XHTML <br />

For a valid XHTML document, all tags must be lowercase. I follow this already in my HTML.

Bad <DIV ID=”sidebar”> Good <div id=”sidebar”>

All pages must have a valid doctype declared, which I do, I just declare HTML.

Strict declaration <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”> Transitional <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> Frameset <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Frameset//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd”>

Attributes can’t be minimized in XHTML, and I don’t minimize them in HTML

Bad <option value=”MO” selected> Good <option value=”MO” selected=”selected”>MO</option>

Also, all attributes must be in quotes.

Bad <table width=90%> Good <table width=”90%”>

Instead of using name, XHTML uses id (also notice I closed the image tag with the /.

bad <img src=”images/myimage.jpg” name=”mainimage” /> good <img src=”images/myimage.jpg” id=”mainimage” />

As you can see XHTML is pretty easy, not too much different from our HTML we already write. For me the transition would just require a change of habit, and really just the addition of some closing “/”s and the changing of my doctype in my site template I always start with. If it means easier compatibility then I might as well start using XHTML now.

Tags: ,

2 Responses to “XHTML vs. HTML”

  1. Jitendra Says:

    January 4th, 2009 at 1:43 am

    if u close img in HTML it gives error in validator

  2. Jason Says:

    January 4th, 2009 at 9:32 am

    That’s because you don’t close your image tags, break tags, horizontal rule tags and others that aren’t paired in HTML 4.01. In XHTML, these closing slashes are required for validation.

Leave a Reply

Name:

Email (will not be published):

Website:

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>