Notification banner Nunjucks macro options

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

Also see the guidance on the Notification banner component page, which shows these options in use within each example.

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

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. The text that displays in the notification banner. You can use any string with this option. If you set html, this option is not required and is ignored.
html string Required. The HTML to use within the notification banner. You can use any string with this option. If you set html, text is not required and is ignored.
caller nunjucks-block Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire notification banner component in a call block.
titleText string The title text that displays in the notification banner. You can use any string with this option. Use this option to set text that does not contain HTML. The available default values are ‘Important’, ‘Success’, and null:
  • if you do not set type, titleText defaults to "Important"
  • if you set type to success, titleText defaults to "Success"
  • if you set titleHtml, this option is ignored
titleHtml string The title HTML to use within the notification banner. You can use any string with this option. Use this option to set text that contains HTML. If you set titleHtml, the titleText option is ignored.
titleHeadingLevel string Sets heading level for the title only. You can only use values between 1 and 6 with this option. The default is 2.
type string The type of notification to render. You can use only "success" or null values with this option. If you set type to "success", the notification banner sets role to "alert". JavaScript then moves the keyboard focus to the notification banner when the page loads. If you do not set type, the notification banner sets role to "region".
role string Overrides the value of the role attribute for the notification banner. Defaults to "region". If you set type to "success", role defaults to "alert".
titleId string The id for the banner title, and the aria-labelledby attribute in the banner. Defaults to "govuk-notification-banner-title".
disableAutoFocus boolean If you set type to "success", or role to "alert", JavaScript moves the keyboard focus to the notification banner when the page loads. To disable this behaviour, set disableAutoFocus to true.
classes string The classes that you want to add to the notification banner.
attributes object The HTML attributes that you want to add to the notification banner, for example, data attributes.