tags:

views:

114

answers:

3

The HTML spec shows the disabled and checked attributes for input elements like this:

<INPUT disabled name="fred">

Whereas w3schools suggests doing it like this:

<input disabled="disabled" name="fred"  />

Is there some reason to prefer one style over the other or is it just personal preference? I can't decide which I find more "readable," the simpler one or the one that's name/value pair like the other attributes.

+2  A: 

The attribute minimization is a notation that has not been carried over to XML. So if you want better machine-readability of the document (perhaps even XML conformance), use the explicit notation.

Martin v. Löwis
+2  A: 

The w3schools example is XHTML compliant. Can't say if that is the intent in writing their content that way, but that is one difference between the two, so if you are comparing w3schools XHTML oriented content to the HTML 4 spec, it makes sense.

Err, after finishing the question and seeing what you were asking, I would say use the HTML version if you don't want/need XHTML compliance, use the latter if you do... or if it doesn't matter for your purposes use whichever you prefer but be consistent.

I Have the Hat
A: 

I've never had an actual need for XHTML, that is, I've never parsed the output of my web apps; still I do my best effort to always generate valid XHTML code, since:

  • it's more human readable than plain old HTML (it's less trivial than it may seem, to determine where a <p> ends, if you don't close the tag);

  • automatic indentation will work better (when I'm not using ASP.NET I'm usually using emacs and nxml-mode);

  • it's cool;

  • I like order, when it doesn't concern my real life (when it does, I hate order, but that's just a problem of mine;).

  • It's easier to debug: invalid XHTML? There surely is an error somewhere.

For all the previous reasons (and for many other ones), I'll always go with:

<input disabled="disabled" name="fred"  />
giorgian