While I was doing some basic HTML I was wondering why Sublime Text 3 always completes required
into required=""
. Like my Instructor in an online course said it is not necessary to set required="true"
or required="false"
but when I set it to false it still requires it.
example code (it will require the field even if it is set tofalse):
<form>
<input type="password" name="password" required="false">
<button>Submit</button>
</form>
I hope you can clear up the confusion. Thanks for every answer.
Farcher
In HTML, the required attribute must be present (the field is required) or absent (the field is NOT required). When the attribute is present, it does not matter what value it has.
About boolean attributes:
A common practice is to use the name of the attribute as its value:
'Required' is a Boolean attribute. It assumes the value of true once it is present. therefore setting it to a 'false' still makes it act as though it was true.
Below is proof
However, if one is handling mouse events, for instance, using JS, they can set the "required" attribute to "True" or "False" using the ".prop()" method. e.g.
OR
required
doesn't take a boolean string. It's required if the attribute exists at all. Sublime is likely expecting some value like most attributes.