How do I show a form's required fields clearly in its markup?
Quick answer
For a supported form control, add the HTML required attribute so it must have a value before submission. Also show people that it is required, for example with “(required)” in its associated label. Associate the label with the input using matching for and id values or by nesting. Don’t rely on color alone or use placeholder text instead of a label. [S1] [S2]
The question, the details, the next step.
A practical checklist
Add
requiredto each supported control that must have a value before submission.Give each field an associated
<label>; match itsforvalue to the input’sid, or nest the input in the label.Show a visible cue such as “(required)” or an asterisk explained in visible instructions.
Do not use color alone to distinguish required fields.
Do not use placeholder text as a replacement for a label.
Check that visible instructions and fields marked
requiredagree.
A few more useful answers
Is `aria-required="true"` enough to make a field mandatory?
No. It communicates required status to assistive technology but does not itself make the field mandatory; use the HTML required attribute for that. [S1]
Can placeholder text serve as the field’s label?
No. Use an associated <label> to identify the field; placeholder text is not a substitute. [S2]
Do I have to write “required” instead of using an asterisk?
You can use an asterisk as a visible cue if you explain its meaning in visible instructions. Don’t rely on color alone. [S1]
Sources
References used for this guide.
- [S1] The required HTML attribute developer.mozilla.org · Checked
- [S2] The HTML input element: Labels and accessible names developer.mozilla.org · Checked
