Skip to main content

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

    {
      "messages": [
        {
          "headingHtml": "Cookies on <span>my service</span>"
        }
      ]
    }
    
    {% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %}
    
    {{ govukCookieBanner({
      "messages": [
        {
          "headingHtml": "Cookies on <span>my service</span>"
        }
      ]
    }) }}
            
  • # heading html as text

    {
      "messages": [
        {
          "headingText": "Cookies on <span>my service</span>"
        }
      ]
    }
    
    {% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %}
    
    {{ govukCookieBanner({
      "messages": [
        {
          "headingText": "Cookies on <span>my service</span>"
        }
      ]
    }) }}
            
  • # 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

    {
      "messages": [
        {
          "classes": "app-my-class"
        }
      ]
    }
    
    {% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %}
    
    {{ govukCookieBanner({
      "messages": [
        {
          "classes": "app-my-class"
        }
      ]
    }) }}
            
  • # attributes

    {
      "messages": [
        {
          "attributes": {
            "data-attribute": "my-value"
          }
        }
      ]
    }
    
    {% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %}
    
    {{ govukCookieBanner({
      "messages": [
        {
          "attributes": {
            "data-attribute": "my-value"
          }
        }
      ]
    }) }}
            
  • # 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

    {
      "messages": [
        {
          "hidden": true
        }
      ]
    }
    
    {% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %}
    
    {{ govukCookieBanner({
      "messages": [
        {
          "hidden": true
        }
      ]
    }) }}
            
  • # hidden false

    {
      "messages": [
        {
          "hidden": false
        }
      ]
    }
    
    {% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %}
    
    {{ govukCookieBanner({
      "messages": [
        {
          "hidden": false
        }
      ]
    }) }}
            
  • # default action

    {
      "messages": [
        {
          "actions": [
            {
              "text": "This is a button"
            }
          ]
        }
      ]
    }
    
    {% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %}
    
    {{ govukCookieBanner({
      "messages": [
        {
          "actions": [
            {
              "text": "This is a button"
            }
          ]
        }
      ]
    }) }}
            
  • {
      "messages": [
        {
          "actions": [
            {
              "text": "This is a link",
              "href": "/link"
            }
          ]
        }
      ]
    }
    
    {% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %}
    
    {{ govukCookieBanner({
      "messages": [
        {
          "actions": [
            {
              "text": "This is a link",
              "href": "/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

    {
      "messages": [
        {
          "actions": [
            {
              "text": "Button",
              "type": "button"
            }
          ]
        }
      ]
    }
    
    {% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %}
    
    {{ govukCookieBanner({
      "messages": [
        {
          "actions": [
            {
              "text": "Button",
              "type": "button"
            }
          ]
        }
      ]
    }) }}
            
  • # 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"
            }
          ]
        }
      ]
    }) }}