Components

Warning text

<div class="govuk-warning-text">
  <span class="govuk-warning-text__icon" aria-hidden="true">!</span>
  <strong class="govuk-warning-text__text">
    <span class="govuk-warning-text__assistive">Warning</span>
    You can be fined up to £5,000 if you do not register.
  </strong>
</div>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
text string Required. If html is set, this is not required. Text to use within the warning text component. If html is provided, the text argument will be ignored.
html string Required. If text is set, this is not required. HTML to use within the warning text component. If html is provided, the text argument will be ignored.
iconFallbackText string Required. The fallback text for the icon.
classes string Classes to add to the warning text.
attributes object HTML attributes (for example data attributes) to add to the warning text.
{% from "warning-text/macro.njk" import govukWarningText %}

{{ govukWarningText({
  text: "You can be fined up to £5,000 if you do not register.",
  iconFallbackText: "Warning"
}) }}

When to use this component

Use the warning text component when you need to warn users about something important, such as legal consequences of an action, or lack of action, that they might take.

How it works

There are 2 ways to use the warning text component. You can use HTML or, if you are using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.

<div class="govuk-warning-text">
  <span class="govuk-warning-text__icon" aria-hidden="true">!</span>
  <strong class="govuk-warning-text__text">
    <span class="govuk-warning-text__assistive">Warning</span>
    You can be fined up to £5,000 if you do not register.
  </strong>
</div>
Nunjucks macro options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

Some options are required for the macro to work; these are marked as "Required" in the option description.

If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.

Primary options
Name Type Description
text string Required. If html is set, this is not required. Text to use within the warning text component. If html is provided, the text argument will be ignored.
html string Required. If text is set, this is not required. HTML to use within the warning text component. If html is provided, the text argument will be ignored.
iconFallbackText string Required. The fallback text for the icon.
classes string Classes to add to the warning text.
attributes object HTML attributes (for example data attributes) to add to the warning text.
{% from "warning-text/macro.njk" import govukWarningText %}

{{ govukWarningText({
  text: "You can be fined up to £5,000 if you do not register.",
  iconFallbackText: "Warning"
}) }}

You might need to rewrite the hidden text (‘Warning’ in the example) to make it appropriate for your context.

Research on this component

If you’ve used this component, get in touch to share your user research findings.

Get in touch

If you’ve got a question, idea or suggestion share it in #govuk-design-system on cross-government Slack (open in app) or email the Design System team on govuk-design-system-support@digital.cabinet-office.gov.uk

Discuss ‘Warning text’ on GitHub