We had an interresting conversation today at work regarding the usage of special attributes in HTML namely:
- Disabled
- Checked
- Selected
- All other similar attributes that don’t require a =”same_name” value
Some people at work use:
<td nowrap>
<input disabled>
<option selected>
<input checked>
And it actually works but some others (including me) use:
<td nowrap="nowrap">
<input disabled="disabled">
<option selected="selected">
<input checked="checked">
Both versions work fine and one of the integrators (I’m one of the programmers) says that both validate fine.
What are the cases where one scenario would be better than the other? I was thinking about XML validity when you put the values and code readability when you don’t. Are there any other scenarios or explanations you could add to that?
Thanks
The key question is whether you actually need XML conformance, but then this would be just one of the many details to take care of.
Omitting the value is slightly more readable and looks slightly less foolish (these “Boolean” attributes look foolish when using the full syntax, don’t they?).
There is a small chance of messing things up using the full syntax—when you mistype the value. But validators will catch that.
Some ancient browsers only accepted the minimized syntax. This was long ago, but some of us still have habits based on such things.