Skip to main content
  1. X-GOVUK projects
  2. GOV.UK Components
  3. Title with error prefix

Title with error prefix

If you have a page containing a form, you should add the “Error: ” prefix to the page title if there is a validation error on the page.

This means that screen readers will read it out as soon as possible.

To do this, you can use the title_with_error_prefix helper.

If you are using a Rails form, you can set the error attribute by calling errors.any? on the form object:

= title_with_error_prefix("Personal details", error: @personal_details_form.errors.any?)

Title with an error present

Input

= title_with_error_prefix("Personal details", error: true)
<%= title_with_error_prefix("Personal details", error: true) %>

Output

Error: Personal details
Error: Personal details

Title with an error present

Input

= title_with_error_prefix("Personal details", error: false)
<%= title_with_error_prefix("Personal details", error: false) %>

Output

Personal details
Personal details

Title with a custom error prefix

Input

= title_with_error_prefix("Manylion personol", error: true, error_prefix: "Gwall: ")
<%= title_with_error_prefix("Manylion personol", error: true, error_prefix: "Gwall: ") %>

Output

Gwall: Manylion personol
Gwall: Manylion personol