New in HTML5.

Required HTML For Input Required: Get The Code Now

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
Attribute of
How To Use Input To Create Form Fields In HTML: Easy Tutorial
What does Required HTML For Input Required: Get The Code Now do?
Specifies that the input field is required; disallows form submission and alerts the user if the required field is empty.

Code Example

 <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" >

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