are attributes without value allowed in HTML4?
html, html4
Solution
Boolean Attributes, Yes they are completely valid.
From W3C: (On SGML & HTML)
Some attributes play the role of boolean variables (e.g., the selected attribute for the `OPTION` element). Their appearance in the start tag of an element implies that the value of the attribute is "true". Their absence implies a value of "false".
Boolean attributes may legally take a single value: the name of the attribute itself (e.g., `selected="selected"`).
This states that Boolean attributes are valid in HTML4 as well, but if you use something like, would be invalid.. because that boolean belongs to `option` tag.. Thanks to @Ronni Skansing for clarifying the doubt..
<p selected>Hello</p>
HTML5 Docs :
From W3C :
Empty Attribute Syntax
Certain attributes may be specified by providing just the attribute name, with no value.
From W3C: (HTML 5.1 Nightly )
A number of attributes are boolean attributes. The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.
BUT
`section` is an invalid attribute, if you want to define your own attributes, HTML5 provides a way to do that.. you need to use `data-` prefix, for example, your `section` should be written as `data-section`, this way your attribute will be counted as valid.
If you hesitate to do so, we always have a validator to check - W3C Markup Validation Service
^ Validated As HTML5
NOTE: Though I provided `data-` is applicable for HTML5, using custom attributes in HTML4 is invalid, no matter even if you define `data-` before the attribute name, but, boolean attributes are valid in HTML4 as well.
Problem
I wonder if HTML 4 allows attributes without value, as being equivalent to attributes with an empty value. For example: ``` <h2 section>foobar</h2> ``` instead of:`<h2 section="">foobar</h2>` Are the two snippets equally valid? If not, are they valid in HTML version 5? thanks!