What are Boolean Attribute in HTML ?


A number of attributes are boolean attributes 1).

  • The presence of a boolean attribute on an element represents the true value,
  • The absence of the attribute represents the false value.


The values true and false are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.

Example with the defer attribute

  • For true
<script defer/>
  • For false

If you use a XML library and that you try to enforce xhtml, you may get an error saying that a value is mandatory

Setting the value to true does not follow the HTML specification but XML one

<!-- not html compliant, only xhtml/xml compliant -->
<script defer="true"/>

You need to set the doctype accordingly


Here is an example of a checkbox that is checked and disabled. The checked and disabled attributes are the boolean attributes.

<label><input type=checkbox checked name=cheese disabled> Cheese</label>

This could be equivalently written as this:

<label><input type=checkbox checked=checked name=cheese disabled=disabled> Cheese</label>

You can also mix styles; the following is still equivalent

<label><input type='checkbox' checked name=cheese disabled=""> Cheese</label>

Powered by ComboStrap