Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For which html5 attributes is the "empty attribute syntax" allowed?

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.

like image 355
Bergi Avatar asked Nov 01 '25 23:11

Bergi


1 Answers

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.

like image 117
BoltClock Avatar answered Nov 03 '25 15:11

BoltClock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!