Form error messages
To notify a user of an error with their form submission:
- Prefix the word “Error:” to the document’s
<title>. It’s the first thing announced by screen readers when the page loads. - Place an error summary at the top of the page
- Add the
.field-errorclass: check the examples that follow to see where to add it (this is slightly different for checkbox and radio inputs). - Provide an inline error message: check the examples that follow to see where to add it (this is slightly different for checkbox and radio inputs).
- Add the
aria-invalidattribute to each input where validation has failed (except for radio buttons). Remove it when validation is successful.
Top tips
Error summary considerations
- The error summary should be at the top of the
mainelement. If the page includes breadcrumbs or a back link, place it after these, but before theh1. - The error summary must start with the heading “There are X problems with this request”, where X is a number equal to the number of validation errors. Wrap the heading in
<div role="alert">to help make sure it’s announced by screen readers. - Link each item in the summary list to the input with the validation error. Use the same wording for both the error summary link and the inline error message.
- Move keyboard focus to the first link in the error summary (Amplify includes JavaScript that will shift keyboard focus if an error summary is present.
Inline error message
- Use
<p class="field-error-msg">to provide the error message. Check the examples that follow to see where to add it (this is slightly different for checkbox and radio inputs). - Each instance of
<p class="field-error-msg">must have a unique ID. It is suggested to use the patternid="error-..., replacing the...with some unique wording that relates to the input purpose. - Add the
aria-describedbyattribute to theinputorfieldsetwhich the error message applies to, populating it with the ID of the relevant error message.- If there is already an
aria-describedbyfor hint text, just add the error message ID after the hint text ID, separated by a space. Do not use multiplearia-describedbyattributes.
- If there is already an
Example form showcasing error messages
Error message considerations
In the event of a validation error, the error message should explain what went wrong and how to fix it. Keep the wording clear and concise.
To help screen reader users, the error message includes a visually hidden ‘Error:’ before the error message.