Form with Validation Summary Template
Improve usability and guide users by presenting all form errors in a convenient summary list.
When a user submits an invalid form, this template prevents submission and instead generates a summary box at the top, listing all errors with clickable links to the corresponding fields.

About this Validation Summary Form
For long forms, users might not see an inline error that's off-screen. A validation summary solves this by gathering all errors in one place. This pattern is a major usability win and is recommended by the W3C.
The workflow, managed by JavaScript, is as follows:
- When the user attempts to submit the form, JavaScript prevents the default action.
- It loops through all required fields and checks their validity.
- For each invalid field, it adds its error message to an array and applies an error style to the field itself.
- If there are any errors, the script dynamically builds an unordered list from the array of errors and displays it in a dedicated "summary box" at the top of the form. Each list item is a link that, when clicked, jumps the user's focus directly to the invalid input. The summary box is given
role="alert"
so screen readers will announce it automatically.
Features
- Centralized Error Display: All errors are presented in one easy-to-read list.
- Highly Accessible: The summary box with
role="alert"
immediately informs assistive technology users of what went wrong. The jump-links make navigation to errors trivial. - Improved User Experience: Eliminates the frustration of searching for an unseen error.
- Dynamic & Reusable: The JavaScript automatically detects invalid fields and builds the summary, making it easy to adapt.
Dependencies
Uses pure HTML and CSS, with a self-contained JavaScript block for the validation logic.
Code
Here's the full code for the form with a validation summary: