HTML - Boolean Attribute


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>

Discover More
DOM - HTML vs XML document

The DOM specification gives the distinction between this two type of document: XML documents (ie XHTML) and HTML documents. HTML elements are rarely nested. In a XML file, the subsection (SECT)...
HTML - Attribute

HTML An attribute in HTML is an XML attribute of an HTML element Attribute names are TR/html-markup/documents.htmlcase-insensitive. Classes and IDs are attributes used in the selection of element....
Html Script Async Vs Defer
HTML - Defer attribute

defer is an boolean attribute of script element that indicates to the user agent (browser) that it should execute the script: after the DOM has been created (the HTML document read entirely and has...

Share this page:
Follow us:
Task Runner