Search code examples
htmlrequired

HTML5 required attribute


I have the following input element in a form. When the form is submitted, I don't need a value for this field. However, when I click the submit button for the form, it gives me an error saying 'This is a required field'.

<input required="false"/>

Solution

  • Using required means you need a value for this field.

    If this value is optional, you must not use required.

    As a side note, this is the HTML5 syntax (no value for properties, and no ending slash for autoclose tags) :

    <input required>