Search code examples
htmlattributes

Are empty boolean HTML attributes the same as no value attributes?


Some HTML attributes are described in most docs as not having a value. Examples include:

<script async ...>
<option selected ...>
<input type="checkbox" checked ...>

Is there any functional/semantic difference between those and empty attributes?

<script async="" ...>
<option selected="" ...>
<input type="checkbox" checked="" ...>

I'm asking because I'm using some library to parse the HTML, then manipulating a few nodes, then serializing the nodes back into HTML and the serializer turns the former into the latter.

Is it fine with empty attribute values or should I work on getting the HTML back into the top format above?


Solution

  • Quote from w3c:

    A boolean attribute without a value assigned to it (e.g. checked) is implicitly equivalent to one that has the empty string assigned to it (i.e. checked=""). As a consequence, it represents the true value.