HTML - Why boolean attributes do not have boolean value?

前端 未结 7 883
小蘑菇
小蘑菇 2020-12-03 10:41

I noticed that some elements have attributes which are boolean. I wonder why the values are not true or false? or 1 and 0? Are there any reason behind why they are like this

7条回答
  •  感动是毒
    2020-12-03 11:11

    The exact definition is:

    Some attributes play the role of boolean variables (e.g., the selected attribute for the OPTION element). Their appearance in the start tag of an element implies that the value of the attribute is "true". Their absence implies a value of "false".

    Also:

    Boolean attributes may legally take a single value: the name of the attribute itself [...] In HTML, boolean attributes may appear in minimized form

    Basically, this implies that there are only two possible statuses for boolean attributes, true and false, but there isn't a not set status.

提交回复
热议问题