Cookie banner examples
-
# default
{ "messages": [ { "headingText": "Cookies on this government service", "text": "We use analytics cookies to help understand how users use our service.", "actions": [ { "text": "Accept analytics cookies", "type": "submit", "name": "cookies", "value": "accept" }, { "text": "Reject analytics cookies", "type": "submit", "name": "cookies", "value": "reject" }, { "text": "View cookie preferences", "href": "/cookie-preferences" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "headingText": "Cookies on this government service", "text": "We use analytics cookies to help understand how users use our service.", "actions": [ { "text": "Accept analytics cookies", "type": "submit", "name": "cookies", "value": "accept" }, { "text": "Reject analytics cookies", "type": "submit", "name": "cookies", "value": "reject" }, { "text": "View cookie preferences", "href": "/cookie-preferences" } ] } ] }) }} -
# accepted confirmation banner
{ "messages": [ { "text": "Your cookie preferences have been saved. You have accepted cookies.", "role": "alert", "actions": [ { "text": "Hide cookie message", "type": "button" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "text": "Your cookie preferences have been saved. You have accepted cookies.", "role": "alert", "actions": [ { "text": "Hide cookie message", "type": "button" } ] } ] }) }} -
# rejected confirmation banner
{ "messages": [ { "text": "Your cookie preferences have been saved. You have rejected cookies.", "role": "alert", "actions": [ { "text": "Hide cookie message", "type": "button" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "text": "Your cookie preferences have been saved. You have rejected cookies.", "role": "alert", "actions": [ { "text": "Hide cookie message", "type": "button" } ] } ] }) }} -
# with html
{ "messages": [ { "headingHtml": "Cookies on <span>my service</span>", "html": "<p class=\"govuk-body\">We use cookies in <span>our service</span>.</p>\n<p class=\"govuk-body\">We’d like to use analytics cookies so we can understand how you use the Design System and make improvements.</p>\n", "actions": [ { "text": "Accept analytics cookies", "type": "submit", "name": "cookies", "value": "accept" }, { "text": "Reject analytics cookies", "type": "submit", "name": "cookies", "value": "reject" }, { "text": "View cookie preferences", "href": "/cookie-preferences" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "headingHtml": "Cookies on <span>my service</span>", "html": "<p class=\"govuk-body\">We use cookies in <span>our service</span>.</p>\n<p class=\"govuk-body\">We’d like to use analytics cookies so we can understand how you use the Design System and make improvements.</p>\n", "actions": [ { "text": "Accept analytics cookies", "type": "submit", "name": "cookies", "value": "accept" }, { "text": "Reject analytics cookies", "type": "submit", "name": "cookies", "value": "reject" }, { "text": "View cookie preferences", "href": "/cookie-preferences" } ] } ] }) }} -
# heading html
-
# heading html as text
-
# html
{ "messages": [ { "html": "<p class=\"govuk-body\">We use cookies in <span>our service</span>.</p>" } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "html": "<p class=\"govuk-body\">We use cookies in <span>our service</span>.</p>" } ] }) }} -
# classes
-
# attributes
-
# custom aria label
{ "ariaLabel": "Cookies on GOV.UK", "messages": [ { "text": "We use cookies on GOV.UK" } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "ariaLabel": "Cookies on GOV.UK", "messages": [ { "text": "We use cookies on GOV.UK" } ] }) }} -
# hidden
-
# hidden false
-
# default action
-
# link
-
# link with false button options
{ "messages": [ { "actions": [ { "text": "This is a link", "href": "/link", "value": "cookies", "name": "link" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "actions": [ { "text": "This is a link", "href": "/link", "value": "cookies", "name": "link" } ] } ] }) }} -
# link as a button
{ "messages": [ { "actions": [ { "text": "This is a link", "href": "/link", "type": "button" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "actions": [ { "text": "This is a link", "href": "/link", "type": "button" } ] } ] }) }} -
# type
-
# button classes
{ "messages": [ { "actions": [ { "text": "Button with custom classes", "classes": "my-button-class app-button-class" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "actions": [ { "text": "Button with custom classes", "classes": "my-button-class app-button-class" } ] } ] }) }} -
# button attributes
{ "messages": [ { "actions": [ { "text": "Button with attributes", "attributes": { "data-button-attribute": "my-value" } } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "actions": [ { "text": "Button with attributes", "attributes": { "data-button-attribute": "my-value" } } ] } ] }) }} -
# link classes
{ "messages": [ { "actions": [ { "text": "Link with custom classes", "href": "/my-link", "classes": "my-link-class app-link-class" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "actions": [ { "text": "Link with custom classes", "href": "/my-link", "classes": "my-link-class app-link-class" } ] } ] }) }} -
# link attributes
{ "messages": [ { "actions": [ { "text": "Link with attributes", "href": "/link", "attributes": { "data-link-attribute": "my-value" } } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "actions": [ { "text": "Link with attributes", "href": "/link", "attributes": { "data-link-attribute": "my-value" } } ] } ] }) }} -
# client-side implementation
{ "messages": [ { "headingText": "Cookies on this service", "text": "We use cookies to help understand how users use our service.", "actions": [ { "text": "Accept analytics cookies", "type": "submit", "name": "cookies", "value": "accept" }, { "text": "Reject analytics cookies", "type": "submit", "name": "cookies", "value": "reject" }, { "text": "View cookie preferences", "href": "/cookie-preferences" } ] }, { "text": "Your cookie preferences have been saved. You have accepted cookies.", "role": "alert", "hidden": true, "actions": [ { "text": "Hide cookie message", "type": "button" } ] }, { "text": "Your cookie preferences have been saved. You have rejected cookies.", "role": "alert", "hidden": true, "actions": [ { "text": "Hide cookie message", "type": "button" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "headingText": "Cookies on this service", "text": "We use cookies to help understand how users use our service.", "actions": [ { "text": "Accept analytics cookies", "type": "submit", "name": "cookies", "value": "accept" }, { "text": "Reject analytics cookies", "type": "submit", "name": "cookies", "value": "reject" }, { "text": "View cookie preferences", "href": "/cookie-preferences" } ] }, { "text": "Your cookie preferences have been saved. You have accepted cookies.", "role": "alert", "hidden": true, "actions": [ { "text": "Hide cookie message", "type": "button" } ] }, { "text": "Your cookie preferences have been saved. You have rejected cookies.", "role": "alert", "hidden": true, "actions": [ { "text": "Hide cookie message", "type": "button" } ] } ] }) }} -
# full banner hidden
{ "hidden": true, "classes": "hide-cookie-banner", "attributes": { "data-hide-cookie-banner": "true" }, "messages": [ { "headingText": "Cookies on this service", "text": "We use cookies to help understand how users use our service.", "actions": [ { "text": "Accept analytics cookies", "type": "submit", "name": "cookies", "value": "accept" }, { "text": "Reject analytics cookies", "type": "submit", "name": "cookies", "value": "reject" }, { "text": "View cookie preferences", "href": "/cookie-preferences" } ] }, { "text": "Your cookie preferences have been saved. You have accepted cookies.", "role": "alert", "actions": [ { "text": "Hide cookie message", "type": "button" } ] }, { "text": "Your cookie preferences have been saved. You have rejected cookies.", "role": "alert", "actions": [ { "text": "Hide cookie message", "type": "button" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "hidden": true, "classes": "hide-cookie-banner", "attributes": { "data-hide-cookie-banner": "true" }, "messages": [ { "headingText": "Cookies on this service", "text": "We use cookies to help understand how users use our service.", "actions": [ { "text": "Accept analytics cookies", "type": "submit", "name": "cookies", "value": "accept" }, { "text": "Reject analytics cookies", "type": "submit", "name": "cookies", "value": "reject" }, { "text": "View cookie preferences", "href": "/cookie-preferences" } ] }, { "text": "Your cookie preferences have been saved. You have accepted cookies.", "role": "alert", "actions": [ { "text": "Hide cookie message", "type": "button" } ] }, { "text": "Your cookie preferences have been saved. You have rejected cookies.", "role": "alert", "actions": [ { "text": "Hide cookie message", "type": "button" } ] } ] }) }} -
# rebrand
{ "messages": [ { "headingText": "Cookies on this government service", "text": "We use analytics cookies to help understand how users use our service.", "actions": [ { "text": "Accept analytics cookies", "type": "submit", "name": "cookies", "value": "accept" }, { "text": "Reject analytics cookies", "type": "submit", "name": "cookies", "value": "reject" }, { "text": "View cookie preferences", "href": "/cookie-preferences" } ] } ] }{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %} {{ govukCookieBanner({ "messages": [ { "headingText": "Cookies on this government service", "text": "We use analytics cookies to help understand how users use our service.", "actions": [ { "text": "Accept analytics cookies", "type": "submit", "name": "cookies", "value": "accept" }, { "text": "Reject analytics cookies", "type": "submit", "name": "cookies", "value": "reject" }, { "text": "View cookie preferences", "href": "/cookie-preferences" } ] } ] }) }}