<divclass="govuk-cookie-banner__message govuk-width-container"><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><h2class="govuk-cookie-banner__heading govuk-heading-m">Cookies on [name of service]</h2><divclass="govuk-cookie-banner__content"><pclass="govuk-body">We use some essential cookies to make this service work.</p><pclass="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p></div></div></div><divclass="govuk-button-group"><buttonvalue="accept"type="button"name="cookies"class="govuk-button"data-module="govuk-button">
Accept analytics cookies
</button><buttonvalue="reject"type="button"name="cookies"class="govuk-button"data-module="govuk-button">
Reject analytics cookies
</button><aclass="govuk-link"href="#">View cookies</a></div></div></div>
<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-cookie-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">ariaLabel</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The text for the <code>aria-label</code> which labels the cookie banner region. This region applies to all messages that the cookie banner includes. For example, the cookie message and the confirmation message. Defaults to 'Cookie banner'.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set this option to <code>true</code>, the whole cookie banner is hidden, including all messages within the banner. You can use <code>hidden</code> for client-side implementations where the cookie banner HTML is present, but hidden until the cookie banner is shown using JavaScript.
</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 additional classes that you want to add to the cookie 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 additional attributes that you want to add to the cookie banner. For example, data attributes.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">messages</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The different messages you can pass into the cookie banner. For example, the cookie message and the confirmation message.
See <a href="#options-default-cookie-banner-example--messages">messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-default-cookie-banner-example--messages">
<caption class="govuk-table__caption govuk-heading-m ">Options for messages</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">headingText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading text that displays in the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">headingHtml</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading HTML to use within the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored. If you are not passing HTML, use <code>headingText</code>.
</td>
</tr>
<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 for the main content within the message. 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">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The HTML for the main content within the message. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored. If you are not passing HTML, use <code>text</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">actions</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
The buttons and links that you want to display in the message. <code>actions</code> defaults to <code>button</code> unless you set <code>href</code>, which renders the action as a link.
See <a href="#options-default-cookie-banner-example--actions">actions</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set it to <code>true</code>, the message is hidden. You can use <code>hidden</code> for client-side implementations where the confirmation message HTML is present, but hidden on the page.
</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 ">
Set <code>role</code> to <code>alert</code> on confirmation messages to allow assistive tech to automatically read the message. You will also need to move focus to the confirmation message using JavaScript you have written yourself.
</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 additional classes that you want to add to the message.
</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 additional attributes that you want to add to the message. For example, data attributes.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-default-cookie-banner-example--actions">
<caption class="govuk-table__caption govuk-heading-m ">Options for actions</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 button or link text.
</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 button. You can set <code>button</code> or <code>submit</code>. Set <code>button</code> and <code>href</code> to render a link styled as a button. If you set <code>href</code>, it overrides <code>submit</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">href</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The <code>href</code> for a link. Set <code>button</code> and <code>href</code> to render a link styled as a button.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The name attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</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 additional classes that you want to add to the button or link.
</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 additional attributes that you want to add to the button or link. For example, data attributes.
</td>
</tr>
</tbody>
</table>
{% set html %}
<p class="govuk-body">We use some essential cookies to make this service work.</p>
<pclass="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p>
{% endset %}
{{ govukCookieBanner({
ariaLabel: "Cookies on [name of service]",
messages: [
{
headingText: "Cookies on [name of service]",
html: html,
actions: [
{
text: "Accept analytics cookies",
type: "button",
name: "cookies",
value: "accept"
},
{
text: "Reject analytics cookies",
type: "button",
name: "cookies",
value: "reject"
},
{
text: "View cookies",
href: "#"
}
]
}
]
}) }}
When to use this component
Use this component if your service sets any cookies on a user’s device.
Remember, you must:
tell users about the cookies your service sets on their device
let users accept or reject any cookies that are not essential to providing your service
The term ‘non-essential cookies’ includes:
HTML5 local storage
service workers
any other technologies that store files on the user’s device
This cookie banner and the cookies page pattern are based on the approach to getting cookie consent used on the GOV.UK website.
This component page shows several options for using a cookie banner, based on the types of cookies you’re using in the service. We also tell you what to cover in your cookie banner, with some text examples.
You must not take the information on this page as legal advice. Your organisation is responsible and accountable for what they do to comply with data protection legislation, such as:
Privacy and Electronic Communications Regulations (PECR)
General Data Protection Regulation (GDPR)
Check with your organisation's privacy expert to see how data protection legislation affects your website and service.
How it works
Show the cookie banner every time the user accesses your service until they either:
accept or reject cookies using the buttons in the cookie banner
save their cookie preferences on the service’s cookies page
Once the user has accepted or rejected cookies, the cookie banner should:
hide the cookie banner message
show a confirmation message — and a 'hide' button to let the user close the banner
set a cookie to save the user’s preferences for 1 year
Make sure the cookie banner does not:
show when the user visits again, once their preferences have been saved
set any non-essential cookies unless the user accepted them on a previous visit
Position the cookie banner after the opening <body> tag and before the ’skip to main content‘ link. If you're using the Nunjucks page template, use the bodyStart block.
Option 1: If you’re only using essential cookies
You can choose not to have a cookie banner if the service only sets essential or 'strictly necessary' cookies, as these do not need user consent.
However, you must tell users that you set essential cookies. You can do this with a cookies page — link to this page in the footer.
Option 2: If you set non-essential cookies on the server
You can choose this option if your service sets non-essential cookies on the server — your service may also set non-essential cookies on the client.
To get consent from the user, display the cookie banner inside a form that lets them submit their choice to accept or reject cookies.
All users will be able to see the banner as this approach does not rely on JavaScript.
Here's an example of a cookie banner inside a form:
<divclass="govuk-cookie-banner "data-nosnippetrole="region"aria-label="Cookies on [name of service]"><divclass="govuk-cookie-banner__message govuk-width-container"><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><h2class="govuk-cookie-banner__heading govuk-heading-m">Cookies on [name of service]</h2><divclass="govuk-cookie-banner__content"><pclass="govuk-body">We use some essential cookies to make this service work.</p><pclass="govuk-body">We’d like to set additional cookies so we can remember your settings, understand how people use the service and make improvements.</p></div></div></div><divclass="govuk-button-group"><buttonvalue="accept"type="submit"name="cookies"class="govuk-button"data-module="govuk-button">
Accept additional cookies
</button><buttonvalue="reject"type="submit"name="cookies"class="govuk-button"data-module="govuk-button">
Reject additional cookies
</button><aclass="govuk-link"href="#">View cookies</a></div></div></div></form>
<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-server-side-implementation-cookie-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">ariaLabel</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The text for the <code>aria-label</code> which labels the cookie banner region. This region applies to all messages that the cookie banner includes. For example, the cookie message and the confirmation message. Defaults to 'Cookie banner'.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set this option to <code>true</code>, the whole cookie banner is hidden, including all messages within the banner. You can use <code>hidden</code> for client-side implementations where the cookie banner HTML is present, but hidden until the cookie banner is shown using JavaScript.
</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 additional classes that you want to add to the cookie 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 additional attributes that you want to add to the cookie banner. For example, data attributes.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">messages</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The different messages you can pass into the cookie banner. For example, the cookie message and the confirmation message.
See <a href="#options-server-side-implementation-cookie-banner-example--messages">messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-server-side-implementation-cookie-banner-example--messages">
<caption class="govuk-table__caption govuk-heading-m ">Options for messages</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">headingText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading text that displays in the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">headingHtml</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading HTML to use within the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored. If you are not passing HTML, use <code>headingText</code>.
</td>
</tr>
<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 for the main content within the message. 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">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The HTML for the main content within the message. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored. If you are not passing HTML, use <code>text</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">actions</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
The buttons and links that you want to display in the message. <code>actions</code> defaults to <code>button</code> unless you set <code>href</code>, which renders the action as a link.
See <a href="#options-server-side-implementation-cookie-banner-example--actions">actions</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set it to <code>true</code>, the message is hidden. You can use <code>hidden</code> for client-side implementations where the confirmation message HTML is present, but hidden on the page.
</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 ">
Set <code>role</code> to <code>alert</code> on confirmation messages to allow assistive tech to automatically read the message. You will also need to move focus to the confirmation message using JavaScript you have written yourself.
</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 additional classes that you want to add to the message.
</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 additional attributes that you want to add to the message. For example, data attributes.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-server-side-implementation-cookie-banner-example--actions">
<caption class="govuk-table__caption govuk-heading-m ">Options for actions</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 button or link text.
</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 button. You can set <code>button</code> or <code>submit</code>. Set <code>button</code> and <code>href</code> to render a link styled as a button. If you set <code>href</code>, it overrides <code>submit</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">href</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The <code>href</code> for a link. Set <code>button</code> and <code>href</code> to render a link styled as a button.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The name attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</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 additional classes that you want to add to the button or link.
</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 additional attributes that you want to add to the button or link. For example, data attributes.
</td>
</tr>
</tbody>
</table>
{% set html %}
<p class="govuk-body">We use some essential cookies to make this service work.</p>
<pclass="govuk-body">We’d like to set additional cookies so we can remember your settings, understand how people use the service and make improvements.</p>
{% endset %}
<form method="POST">
{{ govukCookieBanner({
ariaLabel: "Cookies on [name of service]",
messages: [
{
headingText: "Cookies on [name of service]",
html: html,
actions: [
{
text: "Accept additional cookies",
type: "submit",
name: "cookies",
value: "accept"
},
{
text: "Reject additional cookies",
type: "submit",
name: "cookies",
value: "reject"
},
{
text: "View cookies",
href: "#"
}
]
}
]
}) }}
</form>
Once the user has accepted or rejected cookies and set their cookie preferences, reload the page to show a confirmation message.
Here's an example of a confirmation message inside a form:
<divclass="govuk-cookie-banner "data-nosnippetrole="region"aria-label="Cookies on [name of service]"><divclass="govuk-cookie-banner__message govuk-width-container"><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve accepted additional cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><ahref="#"role="button"draggable="false"class="govuk-button"data-module="govuk-button">
Hide cookie message
</a></div></div></div></form>
<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-server-side-implementation-with-confirmation-cookie-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">ariaLabel</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The text for the <code>aria-label</code> which labels the cookie banner region. This region applies to all messages that the cookie banner includes. For example, the cookie message and the confirmation message. Defaults to 'Cookie banner'.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set this option to <code>true</code>, the whole cookie banner is hidden, including all messages within the banner. You can use <code>hidden</code> for client-side implementations where the cookie banner HTML is present, but hidden until the cookie banner is shown using JavaScript.
</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 additional classes that you want to add to the cookie 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 additional attributes that you want to add to the cookie banner. For example, data attributes.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">messages</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The different messages you can pass into the cookie banner. For example, the cookie message and the confirmation message.
See <a href="#options-server-side-implementation-with-confirmation-cookie-banner-example--messages">messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-server-side-implementation-with-confirmation-cookie-banner-example--messages">
<caption class="govuk-table__caption govuk-heading-m ">Options for messages</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">headingText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading text that displays in the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">headingHtml</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading HTML to use within the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored. If you are not passing HTML, use <code>headingText</code>.
</td>
</tr>
<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 for the main content within the message. 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">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The HTML for the main content within the message. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored. If you are not passing HTML, use <code>text</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">actions</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
The buttons and links that you want to display in the message. <code>actions</code> defaults to <code>button</code> unless you set <code>href</code>, which renders the action as a link.
See <a href="#options-server-side-implementation-with-confirmation-cookie-banner-example--actions">actions</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set it to <code>true</code>, the message is hidden. You can use <code>hidden</code> for client-side implementations where the confirmation message HTML is present, but hidden on the page.
</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 ">
Set <code>role</code> to <code>alert</code> on confirmation messages to allow assistive tech to automatically read the message. You will also need to move focus to the confirmation message using JavaScript you have written yourself.
</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 additional classes that you want to add to the message.
</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 additional attributes that you want to add to the message. For example, data attributes.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-server-side-implementation-with-confirmation-cookie-banner-example--actions">
<caption class="govuk-table__caption govuk-heading-m ">Options for actions</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 button or link text.
</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 button. You can set <code>button</code> or <code>submit</code>. Set <code>button</code> and <code>href</code> to render a link styled as a button. If you set <code>href</code>, it overrides <code>submit</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">href</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The <code>href</code> for a link. Set <code>button</code> and <code>href</code> to render a link styled as a button.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The name attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</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 additional classes that you want to add to the button or link.
</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 additional attributes that you want to add to the button or link. For example, data attributes.
</td>
</tr>
</tbody>
</table>
{% set acceptHtml %}
<p class="govuk-body">You’ve accepted additional cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
<form method="POST">
{{ govukCookieBanner({
ariaLabel: "Cookies on [name of service]",
messages: [
{
html: acceptHtml,
actions: [
{
text: "Hide cookie message",
href: "#",
type: "button"
}
]
}
]
}) }}
</form>
Show the same message to all users
In the cookie banner, tell the user about all the cookies you’re using in the service — whether they've enabled JavaScript or not. This way, you will not need to ask the user to give their consent again on their next visit.
Help users keep their place using progressive enhancement
If the user is entering information into a form as part of the service, they might lose their place when they submit their choice to accept or reject cookies.
To help users running JavaScript on their device, you can write some JavaScript code to let them submit their choice and prevent the page from reloading.
Include all possible messages that the user could see in the cookie banner when the page loads. Hide these with the hidden HTML attribute where needed.
Here's an example of a progressively enhanced cookie banner that includes all possible messages which are hidden using HTML — the cookie banner message is shown using JavaScript to remove the hidden attribute:
<div class="app-example app-example--tabs">
<div class="app-example__toolbar">
<a href="/components/cookie-banner/server-side-multiple-messages-question-visible/index.html" class="app-example__new-window" target="_blank">
Open this
<span class="govuk-visually-hidden">server-side implementation with multiple messages and question visible – cookie banner</span>
example in a new tab
</a>
</div>
<iframe title="Server-side implementation with multiple messages and question visible – Cookie Banner example" data-module="app-example-frame" class="app-example__frame app-example__frame--resizable" src="/components/cookie-banner/server-side-multiple-messages-question-visible/index.html" frameBorder="0" loading="lazy"></iframe>
</div>
<span id="options-server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example"></span>
<ul class="app-tabs" role="tablist">
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example-html" role="tab" aria-controls="server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example-html" data-track="tab-html">HTML</a></li>
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example-nunjucks" role="tab" aria-controls="server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example-nunjucks" data-track="tab-nunjucks">Nunjucks</a></li>
</ul>
<div class="app-tabs__heading js-tabs__heading"><a href="#server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example-html" aria-controls="server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example-html" data-track="tab-html">HTML</a></div>
<div class="app-tabs__container js-tabs__container" id="server-side-implementation-with-multiple-messages-and-question-visible-cookie-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"><<span class="hljs-name">form</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"POST"</span>></span>
<divclass="govuk-cookie-banner "data-nosnippetrole="region"aria-label="Cookies on [name of service]"><divclass="govuk-cookie-banner__message govuk-width-container"><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><h2class="govuk-cookie-banner__heading govuk-heading-m">Cookies on [name of service]</h2><divclass="govuk-cookie-banner__content"><pclass="govuk-body">We use some essential cookies to make this service work.</p><pclass="govuk-body">We’d like to set additional cookies so we can remember your settings, understand how people use the service and make improvements.</p></div></div></div><divclass="govuk-button-group"><buttonvalue="accept"type="submit"name="cookies"class="govuk-button"data-module="govuk-button">
Accept additional cookies
</button><buttonvalue="reject"type="submit"name="cookies"class="govuk-button"data-module="govuk-button">
Reject additional cookies
</button><aclass="govuk-link"href="#">View cookies</a></div></div><divclass="govuk-cookie-banner__message govuk-width-container"hidden><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve accepted additional cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><ahref="#"role="button"draggable="false"class="govuk-button"data-module="govuk-button">
Hide cookie message
</a></div></div><divclass="govuk-cookie-banner__message govuk-width-container"hidden><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve rejected additional cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><ahref="#"role="button"draggable="false"class="govuk-button"data-module="govuk-button">
Hide cookie message
</a></div></div></div></form>
<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-server-side-implementation-with-multiple-messages-and-question-visible-cookie-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">ariaLabel</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The text for the <code>aria-label</code> which labels the cookie banner region. This region applies to all messages that the cookie banner includes. For example, the cookie message and the confirmation message. Defaults to 'Cookie banner'.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set this option to <code>true</code>, the whole cookie banner is hidden, including all messages within the banner. You can use <code>hidden</code> for client-side implementations where the cookie banner HTML is present, but hidden until the cookie banner is shown using JavaScript.
</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 additional classes that you want to add to the cookie 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 additional attributes that you want to add to the cookie banner. For example, data attributes.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">messages</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The different messages you can pass into the cookie banner. For example, the cookie message and the confirmation message.
See <a href="#options-server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example--messages">messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example--messages">
<caption class="govuk-table__caption govuk-heading-m ">Options for messages</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">headingText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading text that displays in the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">headingHtml</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading HTML to use within the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored. If you are not passing HTML, use <code>headingText</code>.
</td>
</tr>
<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 for the main content within the message. 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">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The HTML for the main content within the message. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored. If you are not passing HTML, use <code>text</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">actions</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
The buttons and links that you want to display in the message. <code>actions</code> defaults to <code>button</code> unless you set <code>href</code>, which renders the action as a link.
See <a href="#options-server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example--actions">actions</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set it to <code>true</code>, the message is hidden. You can use <code>hidden</code> for client-side implementations where the confirmation message HTML is present, but hidden on the page.
</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 ">
Set <code>role</code> to <code>alert</code> on confirmation messages to allow assistive tech to automatically read the message. You will also need to move focus to the confirmation message using JavaScript you have written yourself.
</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 additional classes that you want to add to the message.
</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 additional attributes that you want to add to the message. For example, data attributes.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-server-side-implementation-with-multiple-messages-and-question-visible-cookie-banner-example--actions">
<caption class="govuk-table__caption govuk-heading-m ">Options for actions</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 button or link text.
</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 button. You can set <code>button</code> or <code>submit</code>. Set <code>button</code> and <code>href</code> to render a link styled as a button. If you set <code>href</code>, it overrides <code>submit</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">href</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The <code>href</code> for a link. Set <code>button</code> and <code>href</code> to render a link styled as a button.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The name attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</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 additional classes that you want to add to the button or link.
</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 additional attributes that you want to add to the button or link. For example, data attributes.
</td>
</tr>
</tbody>
</table>
{% set html %}
<p class="govuk-body">We use some essential cookies to make this service work.</p>
<pclass="govuk-body">We’d like to set additional cookies so we can remember your settings, understand how people use the service and make improvements.</p>
{% endset %}
{% set acceptHtml %}
<p class="govuk-body">You’ve accepted additional cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
{% set rejectedHtml %}
<p class="govuk-body">You’ve rejected additional cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
<form method="POST">
{{ govukCookieBanner({
ariaLabel: "Cookies on [name of service]",
messages: [
{
headingText: "Cookies on [name of service]",
html: html,
actions: [
{
text: "Accept additional cookies",
type: "submit",
name: "cookies",
value: "accept"
},
{
text: "Reject additional cookies",
type: "submit",
name: "cookies",
value: "reject"
},
{
text: "View cookies",
href: "#"
}
]
},
{
html: acceptHtml,
actions: [
{
text: "Hide cookie message",
href: "#",
type: "button"
}
],
hidden: true
},
{
html: rejectedHtml,
actions: [
{
text: "Hide cookie message",
href: "#",
type: "button"
}
],
hidden: true
}
]
}) }}
</form>
Here's the same example of a progressively enhanced cookie banner, with the confirmation message shown instead:
<div class="app-example app-example--tabs">
<div class="app-example__toolbar">
<a href="/components/cookie-banner/server-side-multiple-messages-confirmation-visible/index.html" class="app-example__new-window" target="_blank">
Open this
<span class="govuk-visually-hidden">server-side implementation with multiple messages and confirmation visible – cookie banner</span>
example in a new tab
</a>
</div>
<iframe title="Server-side implementation with multiple messages and confirmation visible – Cookie Banner example" data-module="app-example-frame" class="app-example__frame app-example__frame--resizable" src="/components/cookie-banner/server-side-multiple-messages-confirmation-visible/index.html" frameBorder="0" loading="lazy"></iframe>
</div>
<span id="options-server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example"></span>
<ul class="app-tabs" role="tablist">
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example-html" role="tab" aria-controls="server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example-html" data-track="tab-html">HTML</a></li>
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example-nunjucks" role="tab" aria-controls="server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example-nunjucks" data-track="tab-nunjucks">Nunjucks</a></li>
</ul>
<div class="app-tabs__heading js-tabs__heading"><a href="#server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example-html" aria-controls="server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example-html" data-track="tab-html">HTML</a></div>
<div class="app-tabs__container js-tabs__container" id="server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-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"><<span class="hljs-name">form</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"POST"</span>></span>
<divclass="govuk-cookie-banner "data-nosnippetrole="region"aria-label="Cookies on [name of service]"><divclass="govuk-cookie-banner__message govuk-width-container"hidden><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><h2class="govuk-cookie-banner__heading govuk-heading-m">Cookies on [name of service]</h2><divclass="govuk-cookie-banner__content"><pclass="govuk-body">We use some essential cookies to make this service work.</p><pclass="govuk-body">We’d like to set additional cookies so we can remember your settings, understand how people use the service and make improvements.</p></div></div></div><divclass="govuk-button-group"><buttonvalue="accept"type="submit"name="cookies"class="govuk-button"data-module="govuk-button">
Accept additional cookies
</button><buttonvalue="reject"type="submit"name="cookies"class="govuk-button"data-module="govuk-button">
Reject additional cookies
</button><aclass="govuk-link"href="#">View cookies</a></div></div><divclass="govuk-cookie-banner__message govuk-width-container"><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve accepted additional cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><ahref="#"role="button"draggable="false"class="govuk-button"data-module="govuk-button">
Hide cookie message
</a></div></div><divclass="govuk-cookie-banner__message govuk-width-container"hidden><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve rejected additional cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><ahref="#"role="button"draggable="false"class="govuk-button"data-module="govuk-button">
Hide cookie message
</a></div></div></div></form>
<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-server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-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">ariaLabel</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The text for the <code>aria-label</code> which labels the cookie banner region. This region applies to all messages that the cookie banner includes. For example, the cookie message and the confirmation message. Defaults to 'Cookie banner'.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set this option to <code>true</code>, the whole cookie banner is hidden, including all messages within the banner. You can use <code>hidden</code> for client-side implementations where the cookie banner HTML is present, but hidden until the cookie banner is shown using JavaScript.
</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 additional classes that you want to add to the cookie 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 additional attributes that you want to add to the cookie banner. For example, data attributes.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">messages</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The different messages you can pass into the cookie banner. For example, the cookie message and the confirmation message.
See <a href="#options-server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example--messages">messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example--messages">
<caption class="govuk-table__caption govuk-heading-m ">Options for messages</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">headingText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading text that displays in the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">headingHtml</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading HTML to use within the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored. If you are not passing HTML, use <code>headingText</code>.
</td>
</tr>
<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 for the main content within the message. 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">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The HTML for the main content within the message. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored. If you are not passing HTML, use <code>text</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">actions</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
The buttons and links that you want to display in the message. <code>actions</code> defaults to <code>button</code> unless you set <code>href</code>, which renders the action as a link.
See <a href="#options-server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example--actions">actions</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set it to <code>true</code>, the message is hidden. You can use <code>hidden</code> for client-side implementations where the confirmation message HTML is present, but hidden on the page.
</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 ">
Set <code>role</code> to <code>alert</code> on confirmation messages to allow assistive tech to automatically read the message. You will also need to move focus to the confirmation message using JavaScript you have written yourself.
</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 additional classes that you want to add to the message.
</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 additional attributes that you want to add to the message. For example, data attributes.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-server-side-implementation-with-multiple-messages-and-confirmation-visible-cookie-banner-example--actions">
<caption class="govuk-table__caption govuk-heading-m ">Options for actions</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 button or link text.
</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 button. You can set <code>button</code> or <code>submit</code>. Set <code>button</code> and <code>href</code> to render a link styled as a button. If you set <code>href</code>, it overrides <code>submit</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">href</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The <code>href</code> for a link. Set <code>button</code> and <code>href</code> to render a link styled as a button.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The name attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</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 additional classes that you want to add to the button or link.
</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 additional attributes that you want to add to the button or link. For example, data attributes.
</td>
</tr>
</tbody>
</table>
{% set html %}
<p class="govuk-body">We use some essential cookies to make this service work.</p>
<pclass="govuk-body">We’d like to set additional cookies so we can remember your settings, understand how people use the service and make improvements.</p>
{% endset %}
{% set acceptHtml %}
<p class="govuk-body">You’ve accepted additional cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
{% set rejectedHtml %}
<p class="govuk-body">You’ve rejected additional cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
<form method="POST">
{{ govukCookieBanner({
ariaLabel: "Cookies on [name of service]",
messages: [
{
headingText: "Cookies on [name of service]",
html: html,
hidden: true,
actions: [
{
text: "Accept additional cookies",
type: "submit",
name: "cookies",
value: "accept"
},
{
text: "Reject additional cookies",
type: "submit",
name: "cookies",
value: "reject"
},
{
text: "View cookies",
href: "#"
}
]
},
{
html: acceptHtml,
actions: [
{
text: "Hide cookie message",
href: "#",
type: "button"
}
]
},
{
html: rejectedHtml,
actions: [
{
text: "Hide cookie message",
href: "#",
type: "button"
}
],
hidden: true
}
]
}) }}
</form>
Option 3: If you set non-essential cookies, but only on the client
You can choose to make your banner only work with JavaScript if your service only needs to set non-essential cookies on the client.
When the page loads, the hidden html attribute hides the component, as well as all the cookie banner messages it contains, which the user might otherwise see.
Show the cookie banner only to users that have enabled JavaScript
Use JavaScript to show cookie banner messages to users that have not accepted or rejected cookies by removing the hidden attribute as needed.
Write your own JavaScript code so that when the user accepts or rejects cookies, the cookie banner will:
hide the cookie message by adding the hidden attribute
show a confirmation message by removing its hidden attribute
give the confirmation message the tabindex="-1" and role="alert" attributes — this will allow the element to be focused so assistive technology can read the message
<divclass="govuk-cookie-banner__message govuk-width-container"><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><h2class="govuk-cookie-banner__heading govuk-heading-m">Cookies on [name of service]</h2><divclass="govuk-cookie-banner__content"><pclass="govuk-body">We use some essential cookies to make this service work.</p><pclass="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p></div></div></div><divclass="govuk-button-group"><buttontype="button"class="govuk-button"data-module="govuk-button">
Accept analytics cookies
</button><buttontype="button"class="govuk-button"data-module="govuk-button">
Reject analytics cookies
</button><aclass="govuk-link"href="#">View cookies</a></div></div><divclass="govuk-cookie-banner__message govuk-width-container"role="alert"hidden><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve accepted analytics cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><buttonclass="govuk-button"data-module="govuk-button">
Hide cookie message
</button></div></div><divclass="govuk-cookie-banner__message govuk-width-container"role="alert"hidden><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve rejected analytics cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><buttonclass="govuk-button"data-module="govuk-button">
Hide cookie message
</button></div></div></div>
<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-client-side-implementation-cookie-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">ariaLabel</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The text for the <code>aria-label</code> which labels the cookie banner region. This region applies to all messages that the cookie banner includes. For example, the cookie message and the confirmation message. Defaults to 'Cookie banner'.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set this option to <code>true</code>, the whole cookie banner is hidden, including all messages within the banner. You can use <code>hidden</code> for client-side implementations where the cookie banner HTML is present, but hidden until the cookie banner is shown using JavaScript.
</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 additional classes that you want to add to the cookie 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 additional attributes that you want to add to the cookie banner. For example, data attributes.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">messages</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The different messages you can pass into the cookie banner. For example, the cookie message and the confirmation message.
See <a href="#options-client-side-implementation-cookie-banner-example--messages">messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-client-side-implementation-cookie-banner-example--messages">
<caption class="govuk-table__caption govuk-heading-m ">Options for messages</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">headingText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading text that displays in the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">headingHtml</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading HTML to use within the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored. If you are not passing HTML, use <code>headingText</code>.
</td>
</tr>
<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 for the main content within the message. 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">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The HTML for the main content within the message. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored. If you are not passing HTML, use <code>text</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">actions</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
The buttons and links that you want to display in the message. <code>actions</code> defaults to <code>button</code> unless you set <code>href</code>, which renders the action as a link.
See <a href="#options-client-side-implementation-cookie-banner-example--actions">actions</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set it to <code>true</code>, the message is hidden. You can use <code>hidden</code> for client-side implementations where the confirmation message HTML is present, but hidden on the page.
</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 ">
Set <code>role</code> to <code>alert</code> on confirmation messages to allow assistive tech to automatically read the message. You will also need to move focus to the confirmation message using JavaScript you have written yourself.
</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 additional classes that you want to add to the message.
</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 additional attributes that you want to add to the message. For example, data attributes.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-client-side-implementation-cookie-banner-example--actions">
<caption class="govuk-table__caption govuk-heading-m ">Options for actions</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 button or link text.
</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 button. You can set <code>button</code> or <code>submit</code>. Set <code>button</code> and <code>href</code> to render a link styled as a button. If you set <code>href</code>, it overrides <code>submit</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">href</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The <code>href</code> for a link. Set <code>button</code> and <code>href</code> to render a link styled as a button.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The name attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</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 additional classes that you want to add to the button or link.
</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 additional attributes that you want to add to the button or link. For example, data attributes.
</td>
</tr>
</tbody>
</table>
{% set html %}
<p class="govuk-body">We use some essential cookies to make this service work.</p>
<pclass="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p>
{% endset %}
{% set acceptHtml %}
<p class="govuk-body">You’ve accepted analytics cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
{% set rejectHtml %}
<p class="govuk-body">You’ve rejected analytics cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
{{ govukCookieBanner({
ariaLabel: "Cookies on [name of service]",
messages: [
{
headingText: "Cookies on [name of service]",
html: html,
actions: [
{
text: "Accept analytics cookies",
type: "button"
},
{
text: "Reject analytics cookies",
type: "button"
},
{
text: "View cookies",
href: "#"
}
]
},
{
html: acceptHtml,
role: "alert",
hidden: true,
actions: [
{
text: "Hide cookie message"
}
]
},
{
html: rejectHtml,
role: "alert",
hidden: true,
actions: [
{
text: "Hide cookie message"
}
]
}
]
}) }}
When the user has accepted cookies
Show a confirmation message confirming that the user has either accepted or rejected cookies by removing the hidden attribute.
<divclass="govuk-cookie-banner__message govuk-width-container"hidden><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><h2class="govuk-cookie-banner__heading govuk-heading-m">Cookies on [name of service]</h2><divclass="govuk-cookie-banner__content"><pclass="govuk-body">We use some essential cookies to make this service work.</p><pclass="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p></div></div></div><divclass="govuk-button-group"><buttontype="button"class="govuk-button"data-module="govuk-button">
Accept analytics cookies
</button><buttontype="button"class="govuk-button"data-module="govuk-button">
Reject analytics cookies
</button><aclass="govuk-link"href="#">View cookies</a></div></div><divclass="govuk-cookie-banner__message govuk-width-container"role="alert"><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve accepted analytics cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><buttonclass="govuk-button"data-module="govuk-button">
Hide cookie message
</button></div></div><divclass="govuk-cookie-banner__message govuk-width-container"role="alert"hidden><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve rejected analytics cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><buttonclass="govuk-button"data-module="govuk-button">
Hide cookie message
</button></div></div></div>
<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-accepted-replacement-message-cookie-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">ariaLabel</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The text for the <code>aria-label</code> which labels the cookie banner region. This region applies to all messages that the cookie banner includes. For example, the cookie message and the confirmation message. Defaults to 'Cookie banner'.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set this option to <code>true</code>, the whole cookie banner is hidden, including all messages within the banner. You can use <code>hidden</code> for client-side implementations where the cookie banner HTML is present, but hidden until the cookie banner is shown using JavaScript.
</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 additional classes that you want to add to the cookie 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 additional attributes that you want to add to the cookie banner. For example, data attributes.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">messages</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The different messages you can pass into the cookie banner. For example, the cookie message and the confirmation message.
See <a href="#options-accepted-replacement-message-cookie-banner-example--messages">messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-accepted-replacement-message-cookie-banner-example--messages">
<caption class="govuk-table__caption govuk-heading-m ">Options for messages</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">headingText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading text that displays in the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">headingHtml</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading HTML to use within the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored. If you are not passing HTML, use <code>headingText</code>.
</td>
</tr>
<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 for the main content within the message. 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">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The HTML for the main content within the message. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored. If you are not passing HTML, use <code>text</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">actions</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
The buttons and links that you want to display in the message. <code>actions</code> defaults to <code>button</code> unless you set <code>href</code>, which renders the action as a link.
See <a href="#options-accepted-replacement-message-cookie-banner-example--actions">actions</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set it to <code>true</code>, the message is hidden. You can use <code>hidden</code> for client-side implementations where the confirmation message HTML is present, but hidden on the page.
</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 ">
Set <code>role</code> to <code>alert</code> on confirmation messages to allow assistive tech to automatically read the message. You will also need to move focus to the confirmation message using JavaScript you have written yourself.
</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 additional classes that you want to add to the message.
</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 additional attributes that you want to add to the message. For example, data attributes.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-accepted-replacement-message-cookie-banner-example--actions">
<caption class="govuk-table__caption govuk-heading-m ">Options for actions</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 button or link text.
</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 button. You can set <code>button</code> or <code>submit</code>. Set <code>button</code> and <code>href</code> to render a link styled as a button. If you set <code>href</code>, it overrides <code>submit</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">href</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The <code>href</code> for a link. Set <code>button</code> and <code>href</code> to render a link styled as a button.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The name attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</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 additional classes that you want to add to the button or link.
</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 additional attributes that you want to add to the button or link. For example, data attributes.
</td>
</tr>
</tbody>
</table>
{% set html %}
<p class="govuk-body">We use some essential cookies to make this service work.</p>
<pclass="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p>
{% endset %}
{% set acceptHtml %}
<p class="govuk-body">You’ve accepted analytics cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
{% set rejectHtml %}
<p class="govuk-body">You’ve rejected analytics cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
{{ govukCookieBanner({
ariaLabel: "Cookies on [name of service]",
messages: [
{
headingText: "Cookies on [name of service]",
html: html,
hidden: true,
actions: [
{
text: "Accept analytics cookies",
type: "button"
},
{
text: "Reject analytics cookies",
type: "button"
},
{
text: "View cookies",
href: "#"
}
]
},
{
html: acceptHtml,
role: "alert",
actions: [
{
text: "Hide cookie message"
}
]
},
{
html: rejectHtml,
role: "alert",
hidden: true,
actions: [
{
text: "Hide cookie message"
}
]
}
]
}) }}
<divclass="govuk-cookie-banner__message govuk-width-container"hidden><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><h2class="govuk-cookie-banner__heading govuk-heading-m">Cookies on [name of service]</h2><divclass="govuk-cookie-banner__content"><pclass="govuk-body">We use some essential cookies to make this service work.</p><pclass="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p></div></div></div><divclass="govuk-button-group"><buttontype="button"class="govuk-button"data-module="govuk-button">
Accept analytics cookies
</button><buttontype="button"class="govuk-button"data-module="govuk-button">
Reject analytics cookies
</button><aclass="govuk-link"href="#">View cookies</a></div></div><divclass="govuk-cookie-banner__message govuk-width-container"role="alert"hidden><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve accepted analytics cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><buttonclass="govuk-button"data-module="govuk-button">
Hide cookie message
</button></div></div><divclass="govuk-cookie-banner__message govuk-width-container"role="alert"><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><divclass="govuk-cookie-banner__content"><pclass="govuk-body">You’ve rejected analytics cookies. You can <aclass="govuk-link"href="#">change your cookie settings</a> at any time.</p></div></div></div><divclass="govuk-button-group"><buttonclass="govuk-button"data-module="govuk-button">
Hide cookie message
</button></div></div></div>
<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-rejected-replacement-message-cookie-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">ariaLabel</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The text for the <code>aria-label</code> which labels the cookie banner region. This region applies to all messages that the cookie banner includes. For example, the cookie message and the confirmation message. Defaults to 'Cookie banner'.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set this option to <code>true</code>, the whole cookie banner is hidden, including all messages within the banner. You can use <code>hidden</code> for client-side implementations where the cookie banner HTML is present, but hidden until the cookie banner is shown using JavaScript.
</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 additional classes that you want to add to the cookie 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 additional attributes that you want to add to the cookie banner. For example, data attributes.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">messages</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The different messages you can pass into the cookie banner. For example, the cookie message and the confirmation message.
See <a href="#options-rejected-replacement-message-cookie-banner-example--messages">messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-rejected-replacement-message-cookie-banner-example--messages">
<caption class="govuk-table__caption govuk-heading-m ">Options for messages</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">headingText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading text that displays in the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">headingHtml</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading HTML to use within the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored. If you are not passing HTML, use <code>headingText</code>.
</td>
</tr>
<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 for the main content within the message. 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">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The HTML for the main content within the message. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored. If you are not passing HTML, use <code>text</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">actions</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
The buttons and links that you want to display in the message. <code>actions</code> defaults to <code>button</code> unless you set <code>href</code>, which renders the action as a link.
See <a href="#options-rejected-replacement-message-cookie-banner-example--actions">actions</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set it to <code>true</code>, the message is hidden. You can use <code>hidden</code> for client-side implementations where the confirmation message HTML is present, but hidden on the page.
</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 ">
Set <code>role</code> to <code>alert</code> on confirmation messages to allow assistive tech to automatically read the message. You will also need to move focus to the confirmation message using JavaScript you have written yourself.
</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 additional classes that you want to add to the message.
</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 additional attributes that you want to add to the message. For example, data attributes.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-rejected-replacement-message-cookie-banner-example--actions">
<caption class="govuk-table__caption govuk-heading-m ">Options for actions</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 button or link text.
</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 button. You can set <code>button</code> or <code>submit</code>. Set <code>button</code> and <code>href</code> to render a link styled as a button. If you set <code>href</code>, it overrides <code>submit</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">href</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The <code>href</code> for a link. Set <code>button</code> and <code>href</code> to render a link styled as a button.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The name attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</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 additional classes that you want to add to the button or link.
</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 additional attributes that you want to add to the button or link. For example, data attributes.
</td>
</tr>
</tbody>
</table>
{% set html %}
<p class="govuk-body">We use some essential cookies to make this service work.</p>
<pclass="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p>
{% endset %}
{% set acceptHtml %}
<p class="govuk-body">You’ve accepted analytics cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
{% set rejectHtml %}
<p class="govuk-body">You’ve rejected analytics cookies. You can <a class="govuk-link" href="#">change your cookie settings</a> at any time.</p>
{% endset %}
{{ govukCookieBanner({
ariaLabel: "Cookies on [name of service]",
messages: [
{
headingText: "Cookies on [name of service]",
html: html,
hidden: true,
actions: [
{
text: "Accept analytics cookies",
type: "button"
},
{
text: "Reject analytics cookies",
type: "button"
},
{
text: "View cookies",
href: "#"
}
]
},
{
html: acceptHtml,
role: "alert",
hidden: true,
actions: [
{
text: "Hide cookie message"
}
]
},
{
html: rejectHtml,
role: "alert",
actions: [
{
text: "Hide cookie message"
}
]
}
]
}) }}
What to cover in your cookie banner
Include the name of the service in the banner heading to help users understand that the cookies you’re talking about are different from the ones set by the main GOV.UK platform.
You’ll need to change the example cookie banner text if your service:
allows third parties to set cookies (tell the user that both your organisation and other organisations will be setting cookies)
uses cookies for reasons other than collecting analytics information or remembering the user’s settings
Keep the text as short as possible while making sure it’s an accurate description of how you use cookies. For example, if you use more than one ‘functional’ cookie and there’s not enough space to mention what each of them does, you could ask for permission to set cookies so ‘you can use as many of the service’s features as possible’.
If you’re using essential cookies and analytics cookies
You can use this example text for a service which sets essential and analytics cookies. Analytics cookies are those set by your organisation to collect information about how people are using your digital service.
<divclass="govuk-cookie-banner__message govuk-width-container"><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><h2class="govuk-cookie-banner__heading govuk-heading-m">Cookies on [name of service]</h2><divclass="govuk-cookie-banner__content"><pclass="govuk-body">We use some essential cookies to make this service work.</p><pclass="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p></div></div></div><divclass="govuk-button-group"><buttonvalue="accept"type="button"name="cookies"class="govuk-button"data-module="govuk-button">
Accept analytics cookies
</button><buttonvalue="reject"type="button"name="cookies"class="govuk-button"data-module="govuk-button">
Reject analytics cookies
</button><aclass="govuk-link"href="#">View cookies</a></div></div></div>
<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-cookie-banner-second-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">ariaLabel</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The text for the <code>aria-label</code> which labels the cookie banner region. This region applies to all messages that the cookie banner includes. For example, the cookie message and the confirmation message. Defaults to 'Cookie banner'.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set this option to <code>true</code>, the whole cookie banner is hidden, including all messages within the banner. You can use <code>hidden</code> for client-side implementations where the cookie banner HTML is present, but hidden until the cookie banner is shown using JavaScript.
</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 additional classes that you want to add to the cookie 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 additional attributes that you want to add to the cookie banner. For example, data attributes.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">messages</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The different messages you can pass into the cookie banner. For example, the cookie message and the confirmation message.
See <a href="#options-default-cookie-banner-second-example--messages">messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-default-cookie-banner-second-example--messages">
<caption class="govuk-table__caption govuk-heading-m ">Options for messages</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">headingText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading text that displays in the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">headingHtml</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading HTML to use within the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored. If you are not passing HTML, use <code>headingText</code>.
</td>
</tr>
<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 for the main content within the message. 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">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The HTML for the main content within the message. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored. If you are not passing HTML, use <code>text</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">actions</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
The buttons and links that you want to display in the message. <code>actions</code> defaults to <code>button</code> unless you set <code>href</code>, which renders the action as a link.
See <a href="#options-default-cookie-banner-second-example--actions">actions</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set it to <code>true</code>, the message is hidden. You can use <code>hidden</code> for client-side implementations where the confirmation message HTML is present, but hidden on the page.
</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 ">
Set <code>role</code> to <code>alert</code> on confirmation messages to allow assistive tech to automatically read the message. You will also need to move focus to the confirmation message using JavaScript you have written yourself.
</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 additional classes that you want to add to the message.
</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 additional attributes that you want to add to the message. For example, data attributes.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-default-cookie-banner-second-example--actions">
<caption class="govuk-table__caption govuk-heading-m ">Options for actions</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 button or link text.
</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 button. You can set <code>button</code> or <code>submit</code>. Set <code>button</code> and <code>href</code> to render a link styled as a button. If you set <code>href</code>, it overrides <code>submit</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">href</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The <code>href</code> for a link. Set <code>button</code> and <code>href</code> to render a link styled as a button.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The name attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</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 additional classes that you want to add to the button or link.
</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 additional attributes that you want to add to the button or link. For example, data attributes.
</td>
</tr>
</tbody>
</table>
{% set html %}
<p class="govuk-body">We use some essential cookies to make this service work.</p>
<pclass="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p>
{% endset %}
{{ govukCookieBanner({
ariaLabel: "Cookies on [name of service]",
messages: [
{
headingText: "Cookies on [name of service]",
html: html,
actions: [
{
text: "Accept analytics cookies",
type: "button",
name: "cookies",
value: "accept"
},
{
text: "Reject analytics cookies",
type: "button",
name: "cookies",
value: "reject"
},
{
text: "View cookies",
href: "#"
}
]
}
]
}) }}
If you’re using more than one type of non-essential cookie
You can use this example text for a service that set:
essential cookies
analytics cookies
functional cookies to remember the user’s settings but are not essential
<div class="app-example app-example--tabs">
<div class="app-example__toolbar">
<a href="/components/cookie-banner/multiple-cookies/index.html" class="app-example__new-window" target="_blank">
Open this
<span class="govuk-visually-hidden">non-essential cookies - cookie banner</span>
example in a new tab
</a>
</div>
<iframe title="Non-essential Cookies - Cookie Banner example" data-module="app-example-frame" class="app-example__frame app-example__frame--resizable" src="/components/cookie-banner/multiple-cookies/index.html" frameBorder="0" loading="lazy"></iframe>
</div>
<span id="options-non-essential-cookies-cookie-banner-example"></span>
<ul class="app-tabs" role="tablist">
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#non-essential-cookies-cookie-banner-example-html" role="tab" aria-controls="non-essential-cookies-cookie-banner-example-html" data-track="tab-html">HTML</a></li>
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#non-essential-cookies-cookie-banner-example-nunjucks" role="tab" aria-controls="non-essential-cookies-cookie-banner-example-nunjucks" data-track="tab-nunjucks">Nunjucks</a></li>
</ul>
<div class="app-tabs__heading js-tabs__heading"><a href="#non-essential-cookies-cookie-banner-example-html" aria-controls="non-essential-cookies-cookie-banner-example-html" data-track="tab-html">HTML</a></div>
<div class="app-tabs__container js-tabs__container" id="non-essential-cookies-cookie-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"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"govuk-cookie-banner "</span> <span class="hljs-attr">data-nosnippet</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"region"</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">"Cookies on [name of service]"</span>></span>
<divclass="govuk-cookie-banner__message govuk-width-container"><divclass="govuk-grid-row"><divclass="govuk-grid-column-two-thirds"><h2class="govuk-cookie-banner__heading govuk-heading-m">Cookies on [name of service]</h2><divclass="govuk-cookie-banner__content"><pclass="govuk-body">We use some essential cookies to make this service work.</p><pclass="govuk-body">We’d like to set additional cookies so we can remember your settings, understand how people use the service and make improvements.</p></div></div></div><divclass="govuk-button-group"><buttonvalue="accept"type="button"name="cookies"class="govuk-button"data-module="govuk-button">
Accept additional cookies
</button><buttonvalue="reject"type="button"name="cookies"class="govuk-button"data-module="govuk-button">
Reject additional cookies
</button><aclass="govuk-link"href="#">View cookies</a></div></div></div>
<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-non-essential-cookies-cookie-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">ariaLabel</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The text for the <code>aria-label</code> which labels the cookie banner region. This region applies to all messages that the cookie banner includes. For example, the cookie message and the confirmation message. Defaults to 'Cookie banner'.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set this option to <code>true</code>, the whole cookie banner is hidden, including all messages within the banner. You can use <code>hidden</code> for client-side implementations where the cookie banner HTML is present, but hidden until the cookie banner is shown using JavaScript.
</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 additional classes that you want to add to the cookie 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 additional attributes that you want to add to the cookie banner. For example, data attributes.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">messages</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The different messages you can pass into the cookie banner. For example, the cookie message and the confirmation message.
See <a href="#options-non-essential-cookies-cookie-banner-example--messages">messages</a>.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-non-essential-cookies-cookie-banner-example--messages">
<caption class="govuk-table__caption govuk-heading-m ">Options for messages</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">headingText</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading text that displays in the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">headingHtml</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The heading HTML to use within the message. You can use any string with this option. If you set <code>headingHtml</code>, <code>headingText</code> is ignored. If you are not passing HTML, use <code>headingText</code>.
</td>
</tr>
<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 for the main content within the message. 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">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
The HTML for the main content within the message. You can use any string with this option. If you set <code>html</code>, <code>text</code> is not required and is ignored. If you are not passing HTML, use <code>text</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">actions</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
The buttons and links that you want to display in the message. <code>actions</code> defaults to <code>button</code> unless you set <code>href</code>, which renders the action as a link.
See <a href="#options-non-essential-cookies-cookie-banner-example--actions">actions</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hidden</th>
<td class="govuk-table__cell ">boolean</td>
<td class="govuk-table__cell ">
Defaults to <code>false</code>. If you set it to <code>true</code>, the message is hidden. You can use <code>hidden</code> for client-side implementations where the confirmation message HTML is present, but hidden on the page.
</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 ">
Set <code>role</code> to <code>alert</code> on confirmation messages to allow assistive tech to automatically read the message. You will also need to move focus to the confirmation message using JavaScript you have written yourself.
</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 additional classes that you want to add to the message.
</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 additional attributes that you want to add to the message. For example, data attributes.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-non-essential-cookies-cookie-banner-example--actions">
<caption class="govuk-table__caption govuk-heading-m ">Options for actions</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 button or link text.
</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 button. You can set <code>button</code> or <code>submit</code>. Set <code>button</code> and <code>href</code> to render a link styled as a button. If you set <code>href</code>, it overrides <code>submit</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">href</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The <code>href</code> for a link. Set <code>button</code> and <code>href</code> to render a link styled as a button.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The name attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
The value attribute for the button. Does not apply if you set <code>href</code>, which makes a link.
</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 additional classes that you want to add to the button or link.
</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 additional attributes that you want to add to the button or link. For example, data attributes.
</td>
</tr>
</tbody>
</table>
{% set html %}
<p class="govuk-body">We use some essential cookies to make this service work.</p>
<pclass="govuk-body">We’d like to set additional cookies so we can remember your settings, understand how people use the service and make improvements.</p>
{% endset %}
{{ govukCookieBanner({
ariaLabel: "Cookies on [name of service]",
messages: [
{
headingText: "Cookies on [name of service]",
html: html,
actions: [
{
text: "Accept additional cookies",
type: "button",
name: "cookies",
value: "accept"
},
{
text: "Reject additional cookies",
type: "button",
name: "cookies",
value: "reject"
},
{
text: "View cookies",
href: "#"
}
]
}
]
}) }}
Creating a cookies page
You’ll need a cookies page as well as a cookie banner.
Research on this component
When the user accepts or rejects cookies, a confirmation message will display. For example, "Your cookie preferences have been saved." The focus also shifts to this new message.
However, a visible focus indicator does not display around the confirmation message. This is different from the notification banner, which does display a visible focus indicator.
We decided to remove the visible focus indicator from the confirmation message for a few reasons, as:
a user cannot interact with it
it's the first element, at the very top of the page
it displays in place of the cookie message, which is the last thing the user interacted with
In this scenario, we assume that a visible focus indicator would be more likely to confuse users than to help them. However, we need more research to prove this.
Help improve this component
To help make sure that this page is useful, relevant and up to date, you can: