/Responsive Web Design

21. Use HTML5 to Require a Field

You can require specific form fields so that your user will not be able to submit your form until he or she has filled them out.

For example, if you wanted to make a text input field required, you can just add the attribute required within your input element, like this:

<input type="text" required>

Challenge

Make your text input a required field, so that your user can't submit the form without completing this field.

Then try to submit the form without inputting any text. See how your HTML5 form notifies you that the field is required?


Prev: 20. Add a Submit Button to a Form

Next: 22. Create a Set of Radio Buttons