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

7

When we insert boolean attributes into elements ( tag ) <html> we do not need to enter the true value, and its simple 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 spellcheck attribute on the html element is without the "true" value, however, the grammar will be checked on any child element of the html root.

Question: Is it correct to use boolean attributes without entering their value? What is the advantage or disadvantage? Any usage convention? Thank you!

    
asked by anonymous 20.03.2016 / 15:57

1 answer

4

Actually the correct one according to specification is that you do not have the < in> string indicating true or false . The main browsers interpret these boolean values, but it is non-standard, it would be an extension. So it's okay to omit it, even though putting it might work in most situations. Specification quotation:

  

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

    
20.03.2016 / 16:29