category | cover | created | tags | title |
---|---|---|---|---|
Practice |
/assets/tips/omit-boolean-attribute-value.png |
2021-04-19 |
HTML |
Omit values of HTML boolean attributes |
There are some HTML boolean attributes such as checked
, disabled
, readonly
, required
, selected
, etc.
According to the HTML specification, a boolean attribute has three possible declarations. All of them have the same effect:
<input readonly />
<input readonly="" />
<input readonly="readonly" />
true
and false
are invalid values:
<!-- Not allowed -->
<button disabled="true">...</button>
<button disabled="false">...</button>
The only way to represent a false
value is to remove the attribute. Hence, to avoid the incorrect and misleading usages, it's recommended to remove the value:
<input readonly />