Component

Error alert

Used at the top of the page, to summarise a unsuccessful user action.

Search for usage of this component on GitHub.

How it looks (preview) (preview all)

How to call this component

<%= render "govuk_publishing_components/components/error_alert", {
  message: "Message to alert the user to a unsuccessful action goes here"
} %>

Accessibility acceptance criteria

  • should be focused on page load, to ensure the message is noticed by assistive tech
  • Should have a role of alert to communicate that is a important and time sensitive message

Other examples

Standard options

This component uses the component wrapper helper. It accepts the following options and applies them to the parent element of the component. See the component wrapper helper documentation for more detail.

  • id - accepts a string for the element ID attribute
  • data_attributes - accepts a hash of data attributes
  • aria - accepts a hash of aria attributes
  • classes - accepts a space separated string of classes, these should not be used for styling and must be prefixed with js-
  • margin_bottom - accepts a number from 0 to 9 (0px to 60px) using the GOV.UK Frontend spacing scale (defaults to no margin)
  • role - accepts a space separated string of roles
  • lang - accepts a language attribute value
  • open - accepts an open attribute value (true or false)
  • hidden - accepts an empty string, ‘hidden’, or ‘until-found’
  • tabindex - accepts an integer. The integer can also be passed as a string.
  • dir - accepts ‘rtl’, ‘ltr’, or ‘auto’.

With message and description (preview)

<%= render "govuk_publishing_components/components/error_alert", {
  message: "Message to alert the user to a unsuccessful action goes here",
  description: "A further description"
} %>

Long example (preview)

<%= render "govuk_publishing_components/components/error_alert", {
  message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut aliquet
    dignissim dui, ac laoreet tortor vulputate nec. Aenean quis turpis
    orci. Proin semper porttitor ipsum, vel maximus justo rutrum vel.
    Morbi volutpat facilisis libero. Donec posuere eget odio non egestas.
    Nullam sed neque quis turpis.
    "
} %>

With data attributes (preview)

The example shown applies a tracking attribute specifically for use by Google Tag Manager in Content Publisher.

Other data attributes can also be applied as required. Note that the component does not include built in tracking. If this is required consider using the GA4 link tracker.

<%= render "govuk_publishing_components/components/error_alert", {
  message: "Message to alert the user to a unsuccessful action goes here",
  description: "A further description",
  data_attributes: {
    tracking: "GTM-123AB"
  }
} %>

With specified id attribute (preview)

<%= render "govuk_publishing_components/components/error_alert", {
  id: "test-id",
  message: "Message to alert the user to a unsuccessful action goes here"
} %>