Reputation: 664444
http://www.w3.org/TR/html-markup/syntax.html#syntax-attr-empty says
Empty attribute syntax
Certain attributes may be specified by providing just the attribute name, with no value [… which] is exactly equivalent to specifying the empty string as the value for the attribute.
IIRC, boolean attributes often use this. However, what does "certain attributes" refer to? In which attributes, on which elements, is this syntax allowed? Or: where is it not allowed?
I could not find a complete list anywhere.
Upvotes: 3
Views: 2642
Reputation: 723588
The empty attribute syntax is just a shorthand for an attribute with a name and an empty-string value, and doesn't mean anything special on its own. So, other than boolean attributes, any attribute that permits empty values, including class
, can be specified with empty attribute syntax, and any attribute that doesn't permit empty values, such as id
and type
, cannot be specified with empty attribute syntax.
You can confirm this by comparing the validation results of the following snippets using Validator.nu.
Both of the following snippets should validate:
<!DOCTYPE html><title>Test</title>
<body class>
<!DOCTYPE html><title>Test</title>
<body class="">
And both of the following snippets should produce the same validation error:
<!DOCTYPE html><title>Test</title>
<body id>
<!DOCTYPE html><title>Test</title>
<body id="">
Error: Bad value for attribute
id
on elementbody
: An ID must not be the empty string.
Upvotes: 5