Refactoring HTML: Improving the Design of Existing Web Applications | 4
Refactoring HTML: Well-Formedness - Part 2
Elliotte Rusty Harold
Fill In Omitted Attribute Value
Add values to all valueless attributes.
XHTML does not support the attribute name-only syntax.
Minimal. Browsers are perfectly happy to read the values you supply.
Omitted attribute values are fairly rare in practice. The only place theyre at all common is in forms and image maps. It may well be possible to manually fix all occurrences on a site without a great deal of effort. Alternatively, you can just use Tidy or TagSoup.
To fix one, just set the attribute value to the name. For example, change this:
Only a few elements and attributes support valueless attributes in the first place:
Because many of the words involved can appear in plain text, it is not safe to use regular expressions to replace these. However, you can use a simple search to find them and then verify and fix them manually. For the attributes that aren't actually English words, such as
mayscript, just search for those words. For the attributes that are, such as
compact, use a regular expression such as this:
Then search for the case where the valueless attribute is the last attribute: