1

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.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375

1 Answers1

4

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 element body: An ID must not be the empty string.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • Hm. Why would the spec explicitly distinguish between "*… or `""` (empty string) or [empty](http://www.w3.org/TR/html-markup/syntax.html#syntax-attr-empty)*" then? – Bergi Oct 05 '15 at 13:46
  • @Bergi: I am not sure. I generally ignore /TR/html-markup now because it has been abandoned by the HTMLWG. (For whatever reason, they don't state or even so much as indicate this on every page, just the [landing page](http://www.w3.org/TR/html-markup).) – BoltClock Oct 05 '15 at 13:53
  • Oh dang, seems Google doesn't know about that and referred me to it nonetheless. And when I check the equivalent section at http://www.w3.org/TR/html5/syntax.html#attributes-0 - oh wonder! - the phrase "*Certain attributes …*" is no more there. Thank you! – Bergi Oct 05 '15 at 14:27