How to Make a Form Field Required in HTML
Add required to a form field, and the browser won't send the form while that field is empty. It stops, points at the field and tells the person what's missing.
Syntax
<input name="<name>" required>
<textarea name="<name>" required></textarea>
| Part | What it does |
|---|---|
required | The field must have a value before the form can be sent. The attribute needs no value of its own. |
<input>, <textarea> | The fields it works on: text boxes, checkboxes, radio buttons and most other input types, plus text areas and lists made with select. |
For a group of radio buttons, required on any one of them makes a choice in the group required. MDN's required page lists every type that supports it.
The Example
The example is a feedback form with two radio buttons, Good and Bad, a Comment text area and a Send button. Both the rating and the comment are required.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Feedback</title>
</head>
<body>
<form>
<p>How was the event?</p>
<label><input type="radio" name="rating" value="good" required> Good</label>
<label><input type="radio" name="rating" value="bad" required> Bad</label>
<p><label for="comment">Comment</label></p>
<textarea id="comment" name="comment" required></textarea>
<p><button type="submit">Send</button></p>
</form>
</body>
</html>
Step 2: Send the Empty Form
Double-click index.html to open it in your browser, and click Send without choosing anything:

The form wasn't sent: the address still ends with index.html.
Step 3: Choose a Rating and Send Again
Click Good, then click Send:

Now the browser points at the comment. The words in the bubbles come from the browser, in its own language: this Chromium runs in British English. The screenshots come from Chromium 159, the open-source browser that Chrome is built on.
Step 4: Fill In the Comment
Type Great talk into the comment box and click Send. This time the form is sent, and the address ends with index.html?rating=good&comment=Great+talk.
What Happened
- The browser checked the required fields in order before sending: first the rating, then the comment.
- Each time it found an empty one, it stopped, showed one message next to it and didn't send the form.
- When both had values, it sent the form as usual.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Expecting required to reject a comment of only spaces | Spaces count as a value: with three spaces in the comment, the form passed the check | Check the text in a script or on the server too |
Relying on required alone to keep bad data out | The check runs in the browser, and it can be switched off: with novalidate on the form, the empty form was sent as ?comment= | Check the values again on the server |
Putting required on only some radio buttons of a group, expecting the others to stay optional | The whole group becomes required: with required on Good only, the form still couldn't be sent until Good or Bad was chosen | Put required on every radio button in the group, or on none, so the code says what it does |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The form won't send and a bubble points at a field | The field is required and empty | Fill it in |
| The form is sent with an empty field | The field doesn't have required, or the form has novalidate | Add required, or remove novalidate |
| A field full of spaces passes the check | required only checks that there's a value | Check the content in a script or on the server |
FAQ
How do I turn the checks off while testing?
Add novalidate to the form: <form novalidate>. The browser then sends the form without checking. The empty form went out as ?comment=, with no rating at all.
Why is the rating missing from the address when nothing is chosen?
A radio group sends nothing when no option is selected, so rating only appears once one is chosen.
Does required work on a checkbox?
Yes. A required checkbox has to be ticked before the form can be sent, which suits a box such as I accept the terms. Unticked, it stopped the form with the message Please tick this box if you want to proceed., and once it was ticked, the form passed the check.
Conclusion
required makes the browser check that a field has a value before it sends the form, and it shows the person which field is missing. It doesn't check what the value is, and it runs only in the browser, so check the data again wherever you store it.
Additional Resources
- HTML attribute: required, on MDN.
- Client-side form validation, on MDN.
