Components

Notification banner
Experimental

This component is currently experimental because more research is needed to validate it.

Use a notification banner to tell the user about something they need to know about, but that’s not directly related to the page content.

<div class="app-example app-example--tabs">
  <div class="app-example__toolbar">
    <a href="/components/notification-banner/default/index.html" class="app-example__new-window" target="_blank">
      Open this
      <span class="govuk-visually-hidden">default – notification banner</span>
      example in a new tab
    </a>
  </div>
  <iframe title="Default – notification banner example" data-module="app-example-frame" class="app-example__frame app-example__frame--resizable app-example__frame--s" src="/components/notification-banner/default/index.html" frameBorder="0" loading="lazy"></iframe>
</div>

<span id="options-default-notification-banner-example"></span>
<ul class="app-tabs" role="tablist">
  <li class="app-tabs__item js-tabs__item" role="presentation"><a href="#default-notification-banner-example-html" role="tab" aria-controls="default-notification-banner-example-html" data-track="tab-html">HTML</a></li>
  <li class="app-tabs__item js-tabs__item" role="presentation"><a href="#default-notification-banner-example-nunjucks" role="tab" aria-controls="default-notification-banner-example-nunjucks" data-track="tab-nunjucks">Nunjucks</a></li>
</ul>

  <div class="app-tabs__heading js-tabs__heading"><a href="#default-notification-banner-example-html" aria-controls="default-notification-banner-example-html" data-track="tab-html">HTML</a></div>

<div class="app-tabs__container js-tabs__container" id="default-notification-banner-example-html" role="tabpanel">
  <div class="app-example__code">
    <pre data-module="app-copy" tabindex="0"><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;govuk-notification-banner&quot;</span> <span class="hljs-attr">role</span>=<span class="hljs-string">&quot;region&quot;</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">&quot;govuk-notification-banner-title&quot;</span> <span class="hljs-attr">data-module</span>=<span class="hljs-string">&quot;govuk-notification-banner&quot;</span>&gt;</span>

<div class="govuk-notification-banner__header"> <h2 class="govuk-notification-banner__title" id="govuk-notification-banner-title"> Important </h2> </div> <div class="govuk-notification-banner__content"> <p class="govuk-notification-banner__heading"> You have 7 days left to send your application. <a class="govuk-notification-banner__link" href="#">View application</a>. </p> </div> </div>

  <div class="app-tabs__heading js-tabs__heading"><a class="app-tabs__heading-link" href="#default-notification-banner-example-nunjucks" aria-controls="default-notification-banner-example-nunjucks" data-track="tab-nunjucks">Nunjucks</a></div>
<div class="app-tabs__container js-tabs__container" id="default-notification-banner-example-nunjucks" role="tabpanel">
    

    <details class="govuk-details app-options" data-module="govuk-details" id="options-default-notification-banner-example-details">
Nunjucks macro options
      <p>
      Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
      </p>
      <p>
      Some options are required for the macro to work; these are marked as "Required" in the option description.
      </p>
      <p>
      If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against  <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
      </p>
      
        <table class="govuk-table app-options__table" id="options-default-notification-banner-example--primary">
          <caption class="govuk-table__caption govuk-heading-m  govuk-visually-hidden">Primary options</caption>
          <thead class="govuk-table__head">
            <tr class="govuk-table__row">
              <th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
              <th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
              <th class="govuk-table__header" scope="col">Description</th>
            </tr>
          </thead>
          <tbody class="govuk-table__body">
            <tr class="govuk-table__row">
                <th class="govuk-table__header" scope="row">text</th>
                <td class="govuk-table__cell ">string</td>
                <td class="govuk-table__cell ">
                  
                    <strong>Required.</strong>
                  
                  The text that displays in the notification banner. You can use any string with this option. If you set <code>html</code>, this option is not required and is ignored.
                  
                  </td>
              </tr>
            <tr class="govuk-table__row">
                <th class="govuk-table__header" scope="row">html</th>
                <td class="govuk-table__cell ">string</td>
                <td class="govuk-table__cell ">
                  
                    <strong>Required.</strong>
                  
                  The HTML to use within the notification banner. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored.
                  
                  </td>
              </tr>
            <tr class="govuk-table__row">
                <th class="govuk-table__header" scope="row">caller</th>
                <td class="govuk-table__cell ">nunjucks-block</td>
                <td class="govuk-table__cell ">
                  
                  Not strictly a parameter but <a href="https://mozilla.github.io/nunjucks/templating.html#call">Nunjucks code convention</a>. Using a <code>call</code> 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 <code>call</code> block.
                  
                  </td>
              </tr>
            <tr class="govuk-table__row">
                <th class="govuk-table__header" scope="row">titleText</th>
                <td class="govuk-table__cell ">string</td>
                <td class="govuk-table__cell ">
                  
                  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 &#39;Important&#39;, &#39;Success&#39;, and null:<ul>
  • 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
  •                   </td>
                  </tr>
                <tr class="govuk-table__row">
                    <th class="govuk-table__header" scope="row">titleHtml</th>
                    <td class="govuk-table__cell ">string</td>
                    <td class="govuk-table__cell ">
                      
                      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 <code>titleHtml</code>, the <code>titleText</code> option is ignored.
                      
                      </td>
                  </tr>
                <tr class="govuk-table__row">
                    <th class="govuk-table__header" scope="row">titleHeadingLevel</th>
                    <td class="govuk-table__cell ">string</td>
                    <td class="govuk-table__cell ">
                      
                      Sets heading level for the title only. You can only use values between <code>1</code> and <code>6</code> with this option. The default is <code>2</code>.
                      
                      </td>
                  </tr>
                <tr class="govuk-table__row">
                    <th class="govuk-table__header" scope="row">type</th>
                    <td class="govuk-table__cell ">string</td>
                    <td class="govuk-table__cell ">
                      
                      The type of notification to render. You can use only the <code>success</code> or null values with this option. If you set <code>type</code> to <code>success</code>, the notification banner sets <code>role</code> to <code>alert</code>. JavaScript then moves the keyboard focus to the notification banner when the page loads. If you do not set <code>type</code>, the notification banner sets <code>role</code> to <code>region</code>.
                      
                      </td>
                  </tr>
                <tr class="govuk-table__row">
                    <th class="govuk-table__header" scope="row">role</th>
                    <td class="govuk-table__cell ">string</td>
                    <td class="govuk-table__cell ">
                      
                      Overrides the value of the <code>role</code> attribute for the notification banner. Defaults to <code>region</code>. If you set <code>type</code> to <code>success</code>, <code>role</code> defaults to <code>alert</code>.
                      
                      </td>
                  </tr>
                <tr class="govuk-table__row">
                    <th class="govuk-table__header" scope="row">titleId</th>
                    <td class="govuk-table__cell ">string</td>
                    <td class="govuk-table__cell ">
                      
                      The <code>id</code> for the banner title, and the <code>aria-labelledby</code> attribute in the banner. Defaults to <code>govuk-notification-banner-title</code>.
                      
                      </td>
                  </tr>
                <tr class="govuk-table__row">
                    <th class="govuk-table__header" scope="row">disableAutoFocus</th>
                    <td class="govuk-table__cell ">boolean</td>
                    <td class="govuk-table__cell ">
                      
                      If you set <code>type</code> to <code>success</code>, or <code>role</code> to <code>alert</code>, JavaScript moves the keyboard focus to the notification banner when the page loads. To disable this behaviour, set <code>disableAutoFocus</code> to <code>true</code>.
                      
                      </td>
                  </tr>
                <tr class="govuk-table__row">
                    <th class="govuk-table__header" scope="row">classes</th>
                    <td class="govuk-table__cell ">string</td>
                    <td class="govuk-table__cell ">
                      
                      The classes that you want to add to the notification banner.
                      
                      </td>
                  </tr>
                <tr class="govuk-table__row">
                    <th class="govuk-table__header" scope="row">attributes</th>
                    <td class="govuk-table__cell ">object</td>
                    <td class="govuk-table__cell ">
                      
                      The HTML attributes that you want to add to the notification banner, for example, data attributes.
                      
                      </td>
                  </tr>
                
              </tbody>
            </table>
    
      <div class="app-example__code">
        <pre data-module="app-copy" tabindex="0"><code class="hljs js">{% <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;govuk/components/notification-banner/macro.njk&quot;</span> <span class="hljs-keyword">import</span> govukNotificationBanner %}
    

    {% set html %} <p class="govuk-notification-banner__heading"> You have 7 days left to send your application. <a class="govuk-notification-banner__link" href="#">View application</a>. </p> {% endset %} {{ govukNotificationBanner({ html: html }) }}