Is it correct to omit the "true" value of the Boolean attributes inserted in the HTML elements?

Asked

Viewed 140 times

7

When we insert attributes Boolean in the elements (tag) <html> we do not need to inform the value true, its mere presence already confirms, by default, that this attribute is active. Example:

<html lang="pt-BR" spellcheck>
   <body>
      <p contenteditable="true">Texto será verificado se conter erros!</p>
   </body>
</html>

Note that the attribute spellcheck in the element html is without the value "true" however, the grammar will be checked on any child element of the root html.

Question: is it correct to use attributes Boolean without stating its value? What is the advantage or disadvantage? Any usage convention? Thank you!

1 answer

4


In fact the correct according to the specification is that it does not have the string indicating true or false. The main browsers interpret these boolean values, but it is out of the standard, it would be an extension. Then it is correct to omit, although putting it can work in most situations. Citation of the specification:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.