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

http://www.w3.org/TR/html-markup/syntax.html#syntax-attr-empty says

Syntax empty attributes

Certain attributes can be specified by specifying the attribute name without a value [... which] is exactly equivalent to specifying an empty string as the value for the attribute.

IIRC, boolean attributes often use this. However, what do "certain attributes" refer to? In which attributes, on which elements, is this syntax allowed? Or: where is it not allowed?

I haven't been able to find a complete list anywhere.

+1


source to share


1 answer


The empty attribute syntax is just shorthand for a name and value attribute with an empty string and doesn't mean anything special on its own. Thus, other than boolean attributes, any attribute that allows null values, including class

, can be specified using the empty attribute syntax, and any attribute that does not allow null values ​​such as id

and type

cannot be specified with the empty attribute syntax.

This can be verified by comparing the validation results of the following snippets using Validator.nu .

Both of the following snippets should check:

<!DOCTYPE html><title>Test</title>
<body class>

      

<!DOCTYPE html><title>Test</title>
<body class="">

      



And both of the following snippets should throw the same validation error:

<!DOCTYPE html><title>Test</title>
<body id>

      

<!DOCTYPE html><title>Test</title>
<body id="">

      

Error: Invalid value for attribute id

for element body

: ID must not be an empty string.

+3


source







All Articles