2

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.

2
  • Apparently, the w3.org/TR/html-markup that I quoted is not HTML5. Hrmpf.
    – Bergi
    Oct 5, 2015 at 14:28
  • Well it was going to be a reference of some sort, not unlike the list you were seeking.
    – BoltClock
    Oct 5, 2015 at 14:33

1 Answer 1

5

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.

3
  • Hm. Why would the spec explicitly distinguish between "… or "" (empty string) or empty" then?
    – Bergi
    Oct 5, 2015 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.)
    – BoltClock
    Oct 5, 2015 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 w3.org/TR/html5/syntax.html#attributes-0 - oh wonder! - the phrase "Certain attributes …" is no more there. Thank you!
    – Bergi
    Oct 5, 2015 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.