I noticed that some elements have attributes which are boolean. I wonder why the values are not true or false? or 1 and 0? Are there any reason behind why they are like this?
<option selected="selected">Ham Burger</option>
or
<input type="button" disabled="disabled" />
Thanks in advance!
If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace. The values "true" and "false" are not allowed on boolean attributes.
Post from May 19, 2020 (↻ May 25, 2022), filed under Web Development. There are Boolean attributes in HTML and, unless I err somewhere, there are two dozen of them. Here's a quick rundown of what makes for a Boolean attribute, and what Boolean attributes there are in current HTML.
To add a Boolean attribute: node. setAttribute(attributeName, ''); // example: document. body.
Correct Option: C Muted is Boolean attribute whose value is set as false by default. Buffered is not boolean attribute in <audio> element.
In SGML, an attribute may be minimized so that its value alone is short for both the name and the value, with the only possible value for the attribute in this case obviously being the attribute's own name. HTML uses this for boolean attributes, where the presence or absence of the attribute is what's meaningful, and its value is irrelevant. But in XML, minimized attributes were disallowed, so we wound up with the awkwardness that is selected="selected"
when XHTML came into vogue. If you're writing HTML rather than XHTML, you can just write selected
.
The exact definition is:
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".
Also:
Boolean attributes may legally take a single value: the name of the attribute itself [...] In HTML, boolean attributes may appear in minimized form
Basically, this implies that there are only two possible statuses for boolean attributes, true and false, but there isn't a not set status.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With