HTML chapters

Chapter 15 of 17

Accessible form validation

Try this in our HTML Compiler →

The idea

required and input types provide browser-side checks but are not server-side security. A real submission needs an action endpoint and validation there too. Avoid collecting personal data in a practice page. Connect explanatory text with aria-describedby when a field needs instructions.

Worked example

<label for="topic">Topic</label>
<input id="topic" name="topic" required aria-describedby="topic-help">
<p id="topic-help">Enter the subject you want to study.</p>

What to check

The field's label and supporting instructions are distinct. A placeholder is not a replacement for a visible label.

Practice task

Add a minimum length of three characters and a visible instruction. Test the field with keyboard navigation.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on