New in HTML5.

<input required>

Attribute of
<input> HTML Tag
What does <input required> do?
Specifies that the input field is required; disallows form submission and alerts the user if the required field is empty.

Code Example

<form>
 <p><i>Try submitting without filling in the field.</i></p>
 <label for="animal">What is your favorite animal?</label><br>
 <input name="animal" id="animal" value="" required><br>
 <input type="submit" >
</form>

Try submitting without filling in the field.



required and data validation

As with all HTML5 in-browser data validation, required should primarily be seen as a UI helper. A malicious user can easily submit a form request that includes or excludes whatever data they want. Data validation and sanitization need to occur on the server, once the data is received.

Adam is a technical writer who specializes in developer documentation and tutorials.

Browser Support for required

1045139 (with problems)9.6