Components

Cookie banner

Experimental

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

Allow users to accept or reject cookies which are not essential to making your service work.

<div
  class="govuk-cookie-banner"
  data-nosnippet="true"
  role="region"
  aria-label="Cookies on [name of service]"
>
  <div
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <h2
          class="govuk-cookie-banner__heading govuk-heading-m"
        >
          Cookies on [name of service]
        </h2>
        <div class="govuk-cookie-banner__content">
          <p class="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p class="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>
    <div class="govuk-button-group">
      <button
        data-module="govuk-button"
        value="accept"
        name="cookies"
        class="govuk-button"
      >
        Accept analytics cookies
      </button>
      <button
        data-module="govuk-button"
        value="reject"
        name="cookies"
        class="govuk-button"
      >
        Reject analytics cookies
      </button>
      <a
        class="govuk-link govuk-link--active"
        href="#"
      >
        View cookies
      </a>
    </div>
  </div>
</div>
<CookieBanner
  aria-label="Cookies on [name of service]"
  messages={[
    {
      heading: "Cookies on [name of service]",
      content: (
        <Fragment>
          <p className="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p className="govuk-body">
            We’d also like to use analytics cookies so
            we can understand how you use the service
            and make improvements.
          </p>
        </Fragment>
      ),
      actions: (
        <Fragment>
          <Button value="accept" name="cookies">
            Accept analytics cookies
          </Button>
          <Button value="reject" name="cookies">
            Reject analytics cookies
          </Button>
          <A href="#">View cookies</A>
        </Fragment>
      ),
    },
  ]}
/>
Props
NameTypeDefaultDescription
idother'id' attribute to place on the base HTML element
classBlockotherBlock name override in BEM style classes applied to all elements
classModifiersotherBEM style modifiers to apply to the base HTML element
classNameotherExtra classes to apply to the base HTML element
defaultCheckedother
defaultValueother
suppressContentEditableWarningother
suppressHydrationWarningother
accessKeyother
autoCapitalizeother
autoFocusother
contentEditableother
contextMenuother
dirother
draggableother
enterKeyHintother
hiddenother
langother
nonceother
slotother
spellCheckother
styleother
tabIndexother
titleother
translateother
radioGroupother
roleother
aboutother
contentother
datatypeother
inlistother
prefixother
propertyother
relother
resourceother
revother
typeofother
vocabother
autoCorrectother
autoSaveother
colorother
itemPropother
itemScopeother
itemTypeother
itemIDother
itemRefother
resultsother
securityother
unselectableother
inputModeotherHints at the type of data that might be entered by the user while editing the element or its contents
isotherSpecify that a standard HTML element should behave like a defined custom built-in element
aria-activedescendantotherIdentifies the currently active element when DOM focus is on a composite widget, textbox, group, or application.
aria-atomicotherIndicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute.
aria-autocompleteotherIndicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be presented if they are made.
aria-braillelabelotherDefines a string value that labels the current element, which is intended to be converted into Braille.
aria-brailleroledescriptionotherDefines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille.
aria-busyother
aria-checkedotherIndicates the current "checked" state of checkboxes, radio buttons, and other widgets.
aria-colcountotherDefines the total number of columns in a table, grid, or treegrid.
aria-colindexotherDefines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid.
aria-colindextextotherDefines a human readable text alternative of aria-colindex.
aria-colspanotherDefines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid.
aria-controlsotherIdentifies the element (or elements) whose contents or presence are controlled by the current element.
aria-currentotherIndicates the element that represents the current item within a container or set of related elements.
aria-describedbyotherIdentifies the element (or elements) that describes the object.
aria-descriptionotherDefines a string value that describes or annotates the current element.
aria-detailsotherIdentifies the element that provides a detailed, extended description for the object.
aria-disabledotherIndicates that the element is perceivable but disabled, so it is not editable or otherwise operable.
aria-dropeffectotherIndicates what functions can be performed when a dragged object is released on the drop target.
aria-errormessageotherIdentifies the element that provides an error message for the object.
aria-expandedotherIndicates whether the element, or another grouping element it controls, is currently expanded or collapsed.
aria-flowtootherIdentifies the next element (or elements) in an alternate reading order of content which, at the user's discretion, allows assistive technology to override the general default of reading in document source order.
aria-grabbedotherIndicates an element's "grabbed" state in a drag-and-drop operation.
aria-haspopupotherIndicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
aria-hiddenotherIndicates whether the element is exposed to an accessibility API.
aria-invalidotherIndicates the entered value does not conform to the format expected by the application.
aria-keyshortcutsotherIndicates keyboard shortcuts that an author has implemented to activate or give focus to an element.
aria-labelotherDefines a string value that labels the current element.
aria-labelledbyotherIdentifies the element (or elements) that labels the current element.
aria-levelotherDefines the hierarchical level of an element within a structure.
aria-liveotherIndicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.
aria-modalotherIndicates whether an element is modal when displayed.
aria-multilineotherIndicates whether a text box accepts multiple lines of input or only a single line.
aria-multiselectableotherIndicates that the user may select more than one item from the current selectable descendants.
aria-orientationotherIndicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.
aria-ownsotherIdentifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship.
aria-placeholderotherDefines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format.
aria-posinsetotherDefines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM.
aria-pressedotherIndicates the current "pressed" state of toggle buttons.
aria-readonlyotherIndicates that the element is not editable, but is otherwise operable.
aria-relevantotherIndicates what notifications the user agent will trigger when the accessibility tree within a live region is modified.
aria-requiredotherIndicates that user input is required on the element before a form may be submitted.
aria-roledescriptionotherDefines a human-readable, author-localized description for the role of an element.
aria-rowcountotherDefines the total number of rows in a table, grid, or treegrid.
aria-rowindexotherDefines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid.
aria-rowindextextotherDefines a human readable text alternative of aria-rowindex.
aria-rowspanotherDefines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid.
aria-selectedotherIndicates the current "selected" state of various widgets.
aria-setsizeotherDefines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM.
aria-sortotherIndicates if items in a table or grid are sorted in ascending or descending order.
aria-valuemaxotherDefines the maximum allowed value for a range widget.
aria-valueminotherDefines the minimum allowed value for a range widget.
aria-valuenowotherDefines the current value for a range widget.
aria-valuetextotherDefines the human readable text alternative of aria-valuenow for a range widget.
dangerouslySetInnerHTMLother
onCopyother
onCopyCaptureother
onCutother
onCutCaptureother
onPasteother
onPasteCaptureother
onCompositionEndother
onCompositionEndCaptureother
onCompositionStartother
onCompositionStartCaptureother
onCompositionUpdateother
onCompositionUpdateCaptureother
onFocusother
onFocusCaptureother
onBlurother
onBlurCaptureother
onChangeother
onChangeCaptureother
onBeforeInputother
onBeforeInputCaptureother
onInputother
onInputCaptureother
onResetother
onResetCaptureother
onSubmitother
onSubmitCaptureother
onInvalidother
onInvalidCaptureother
onLoadother
onLoadCaptureother
onErrorother
onErrorCaptureother
onKeyDownother
onKeyDownCaptureother
onKeyPressother
onKeyPressCaptureother
onKeyUpother
onKeyUpCaptureother
onAbortother
onAbortCaptureother
onCanPlayother
onCanPlayCaptureother
onCanPlayThroughother
onCanPlayThroughCaptureother
onDurationChangeother
onDurationChangeCaptureother
onEmptiedother
onEmptiedCaptureother
onEncryptedother
onEncryptedCaptureother
onEndedother
onEndedCaptureother
onLoadedDataother
onLoadedDataCaptureother
onLoadedMetadataother
onLoadedMetadataCaptureother
onLoadStartother
onLoadStartCaptureother
onPauseother
onPauseCaptureother
onPlayother
onPlayCaptureother
onPlayingother
onPlayingCaptureother
onProgressother
onProgressCaptureother
onRateChangeother
onRateChangeCaptureother
onResizeother
onResizeCaptureother
onSeekedother
onSeekedCaptureother
onSeekingother
onSeekingCaptureother
onStalledother
onStalledCaptureother
onSuspendother
onSuspendCaptureother
onTimeUpdateother
onTimeUpdateCaptureother
onVolumeChangeother
onVolumeChangeCaptureother
onWaitingother
onWaitingCaptureother
onAuxClickother
onAuxClickCaptureother
onClickother
onClickCaptureother
onContextMenuother
onContextMenuCaptureother
onDoubleClickother
onDoubleClickCaptureother
onDragother
onDragCaptureother
onDragEndother
onDragEndCaptureother
onDragEnterother
onDragEnterCaptureother
onDragExitother
onDragExitCaptureother
onDragLeaveother
onDragLeaveCaptureother
onDragOverother
onDragOverCaptureother
onDragStartother
onDragStartCaptureother
onDropother
onDropCaptureother
onMouseDownother
onMouseDownCaptureother
onMouseEnterother
onMouseLeaveother
onMouseMoveother
onMouseMoveCaptureother
onMouseOutother
onMouseOutCaptureother
onMouseOverother
onMouseOverCaptureother
onMouseUpother
onMouseUpCaptureother
onSelectother
onSelectCaptureother
onTouchCancelother
onTouchCancelCaptureother
onTouchEndother
onTouchEndCaptureother
onTouchMoveother
onTouchMoveCaptureother
onTouchStartother
onTouchStartCaptureother
onPointerDownother
onPointerDownCaptureother
onPointerMoveother
onPointerMoveCaptureother
onPointerUpother
onPointerUpCaptureother
onPointerCancelother
onPointerCancelCaptureother
onPointerEnterother
onPointerLeaveother
onPointerOverother
onPointerOverCaptureother
onPointerOutother
onPointerOutCaptureother
onGotPointerCaptureother
onGotPointerCaptureCaptureother
onLostPointerCaptureother
onLostPointerCaptureCaptureother
onScrollother
onScrollCaptureother
onWheelother
onWheelCaptureother
onAnimationStartother
onAnimationStartCaptureother
onAnimationEndother
onAnimationEndCaptureother
onAnimationIterationother
onAnimationIterationCaptureother
onTransitionEndother
onTransitionEndCaptureother
maxContentsWidthotherMaximum width of the contents in px units (-1 for full width)
messagesotherList of messages to display

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.

Before you start

Audit and categorise your cookies as shown in the cookies page pattern to help you choose the best option for your service.

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.

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:

<form method="POST">
  <div
    class="govuk-cookie-banner"
    data-nosnippet="true"
    role="region"
    aria-label="Cookies on [name of service]"
  >
    <div
      class="govuk-width-container govuk-cookie-banner__message"
    >
      <div class="govuk-grid-row">
        <div class="govuk-grid-column-two-thirds">
          <h2
            class="govuk-cookie-banner__heading govuk-heading-m"
          >
            Cookies on [name of service]
          </h2>
          <div class="govuk-cookie-banner__content">
            <p class="govuk-body">
              We use some essential cookies to make
              this service work.
            </p>
            <p class="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>
      <div class="govuk-button-group">
        <button
          data-module="govuk-button"
          value="accept"
          type="submit"
          name="cookies"
          class="govuk-button"
        >
          Accept analytics cookies
        </button>
        <button
          data-module="govuk-button"
          value="reject"
          type="submit"
          name="cookies"
          class="govuk-button"
        >
          Reject analytics cookies
        </button>
        <a
          class="govuk-link govuk-link--active"
          href="#"
        >
          View cookies
        </a>
      </div>
    </div>
  </div>
</form>
<form method="POST">
  <CookieBanner
    aria-label="Cookies on [name of service]"
    messages={[
      {
        heading: "Cookies on [name of service]",
        content: (
          <Fragment>
            <p className="govuk-body">
              We use some essential cookies to make
              this service work.
            </p>
            <p className="govuk-body">
              We’d also like to use analytics cookies
              so we can understand how you use the
              service and make improvements.
            </p>
          </Fragment>
        ),
        actions: (
          <Fragment>
            <Button
              value="accept"
              type="submit"
              name="cookies"
            >
              Accept analytics cookies
            </Button>
            <Button
              value="reject"
              type="submit"
              name="cookies"
            >
              Reject analytics cookies
            </Button>
            <A href="#">View cookies</A>
          </Fragment>
        ),
      },
    ]}
  />
</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:

<form method="POST">
  <div
    class="govuk-cookie-banner"
    data-nosnippet="true"
    role="region"
    aria-label="Cookies on [name of service]"
  >
    <div
      class="govuk-width-container govuk-cookie-banner__message"
    >
      <div class="govuk-grid-row">
        <div class="govuk-grid-column-two-thirds">
          <h2
            class="govuk-cookie-banner__heading govuk-heading-m"
          >
            Cookies on [name of service]
          </h2>
          <div class="govuk-cookie-banner__content">
            <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>
          </div>
        </div>
      </div>
      <div class="govuk-button-group">
        <a
          data-module="govuk-button"
          draggable="false"
          role="button"
          class="govuk-button govuk-button--active"
          href="#"
        >
          Hide this message
        </a>
      </div>
    </div>
  </div>
</form>
<form method="POST">
  <CookieBanner
    aria-label="Cookies on [name of service]"
    messages={[
      {
        heading: "Cookies on [name of service]",
        content: (
          <p className="govuk-body">
            You’ve accepted additional cookies. You
            can{" "}
            <a class="govuk-link" href="#">
              change your cookie settings
            </a>{" "}
            at any time.
          </p>
        ),
        actions: (
          <Button href="#">Hide this message</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:

<form method="POST">
  <div
    class="govuk-cookie-banner"
    data-nosnippet="true"
    role="region"
    aria-label="Cookies on [name of service]"
  >
    <div
      class="govuk-width-container govuk-cookie-banner__message"
    >
      <div class="govuk-grid-row">
        <div class="govuk-grid-column-two-thirds">
          <h2
            class="govuk-cookie-banner__heading govuk-heading-m"
          >
            Cookies on [name of service]
          </h2>
          <div class="govuk-cookie-banner__content">
            <p class="govuk-body">
              We use some essential cookies to make
              this service work.
            </p>
            <p class="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>
      <div class="govuk-button-group">
        <button
          data-module="govuk-button"
          value="accept"
          type="submit"
          name="cookies"
          class="govuk-button"
        >
          Accept analytics cookies
        </button>
        <button
          data-module="govuk-button"
          value="reject"
          type="submit"
          name="cookies"
          class="govuk-button"
        >
          Reject analytics cookies
        </button>
        <a
          class="govuk-link govuk-link--active"
          href="#"
        >
          View cookies
        </a>
      </div>
    </div>
    <div
      hidden=""
      class="govuk-width-container govuk-cookie-banner__message"
    >
      <div class="govuk-grid-row">
        <div class="govuk-grid-column-two-thirds">
          <div class="govuk-cookie-banner__content">
            <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>
          </div>
        </div>
      </div>
      <div class="govuk-button-group">
        <a
          data-module="govuk-button"
          draggable="false"
          role="button"
          class="govuk-button govuk-button--active"
          href="#"
        >
          Hide this message
        </a>
      </div>
    </div>
    <div
      hidden=""
      class="govuk-width-container govuk-cookie-banner__message"
    >
      <div class="govuk-grid-row">
        <div class="govuk-grid-column-two-thirds">
          <div class="govuk-cookie-banner__content">
            <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>
          </div>
        </div>
      </div>
      <div class="govuk-button-group">
        <a
          data-module="govuk-button"
          draggable="false"
          role="button"
          class="govuk-button govuk-button--active"
          href="#"
        >
          Hide this message
        </a>
      </div>
    </div>
  </div>
</form>
<form method="POST">
  <CookieBanner
    aria-label="Cookies on [name of service]"
    messages={[
      {
        heading: "Cookies on [name of service]",
        content: (
          <Fragment>
            <p className="govuk-body">
              We use some essential cookies to make
              this service work.
            </p>
            <p className="govuk-body">
              We’d also like to use analytics cookies
              so we can understand how you use the
              service and make improvements.
            </p>
          </Fragment>
        ),
        actions: (
          <Fragment>
            <Button
              value="accept"
              type="submit"
              name="cookies"
            >
              Accept analytics cookies
            </Button>
            <Button
              value="reject"
              type="submit"
              name="cookies"
            >
              Reject analytics cookies
            </Button>
            <A href="#">View cookies</A>
          </Fragment>
        ),
      },
      {
        content: (
          <p className="govuk-body">
            You’ve accepted additional cookies. You
            can{" "}
            <a class="govuk-link" href="#">
              change your cookie settings
            </a>{" "}
            at any time.
          </p>
        ),
        actions: (
          <Button href="#">Hide this message</Button>
        ),
        hidden: true,
      },
      {
        content: (
          <p className="govuk-body">
            You’ve rejected additional cookies. You
            can{" "}
            <a class="govuk-link" href="#">
              change your cookie settings
            </a>{" "}
            at any time.
          </p>
        ),
        actions: (
          <Button href="#">Hide this message</Button>
        ),
        hidden: true,
      },
    ]}
  />
</form>

Here’s the same example of a progressively enhanced cookie banner, with the confirmation message shown instead:

<form method="POST">
  <div
    class="govuk-cookie-banner"
    data-nosnippet="true"
    role="region"
    aria-label="Cookies on [name of service]"
  >
    <div
      hidden=""
      class="govuk-width-container govuk-cookie-banner__message"
    >
      <div class="govuk-grid-row">
        <div class="govuk-grid-column-two-thirds">
          <h2
            class="govuk-cookie-banner__heading govuk-heading-m"
          >
            Cookies on [name of service]
          </h2>
          <div class="govuk-cookie-banner__content">
            <p class="govuk-body">
              We use some essential cookies to make
              this service work.
            </p>
            <p class="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>
      <div class="govuk-button-group">
        <button
          data-module="govuk-button"
          value="accept"
          type="submit"
          name="cookies"
          class="govuk-button"
        >
          Accept analytics cookies
        </button>
        <button
          data-module="govuk-button"
          value="reject"
          type="submit"
          name="cookies"
          class="govuk-button"
        >
          Reject analytics cookies
        </button>
        <a
          class="govuk-link govuk-link--active"
          href="#"
        >
          View cookies
        </a>
      </div>
    </div>
    <div
      class="govuk-width-container govuk-cookie-banner__message"
    >
      <div class="govuk-grid-row">
        <div class="govuk-grid-column-two-thirds">
          <div class="govuk-cookie-banner__content">
            <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>
          </div>
        </div>
      </div>
      <div class="govuk-button-group">
        <a
          data-module="govuk-button"
          draggable="false"
          role="button"
          class="govuk-button govuk-button--active"
          href="#"
        >
          Hide this message
        </a>
      </div>
    </div>
    <div
      hidden=""
      class="govuk-width-container govuk-cookie-banner__message"
    >
      <div class="govuk-grid-row">
        <div class="govuk-grid-column-two-thirds">
          <div class="govuk-cookie-banner__content">
            <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>
          </div>
        </div>
      </div>
      <div class="govuk-button-group">
        <a
          data-module="govuk-button"
          draggable="false"
          role="button"
          class="govuk-button govuk-button--active"
          href="#"
        >
          Hide this message
        </a>
      </div>
    </div>
  </div>
</form>
<form method="POST">
  <CookieBanner
    aria-label="Cookies on [name of service]"
    messages={[
      {
        heading: "Cookies on [name of service]",
        content: (
          <Fragment>
            <p className="govuk-body">
              We use some essential cookies to make
              this service work.
            </p>
            <p className="govuk-body">
              We’d also like to use analytics cookies
              so we can understand how you use the
              service and make improvements.
            </p>
          </Fragment>
        ),
        actions: (
          <Fragment>
            <Button
              value="accept"
              type="submit"
              name="cookies"
            >
              Accept analytics cookies
            </Button>
            <Button
              value="reject"
              type="submit"
              name="cookies"
            >
              Reject analytics cookies
            </Button>
            <A href="#">View cookies</A>
          </Fragment>
        ),
        hidden: true,
      },
      {
        content: (
          <p className="govuk-body">
            You’ve accepted additional cookies. You
            can{" "}
            <a class="govuk-link" href="#">
              change your cookie settings
            </a>{" "}
            at any time.
          </p>
        ),
        actions: (
          <Button href="#">Hide this message</Button>
        ),
      },
      {
        content: (
          <p className="govuk-body">
            You’ve rejected additional cookies. You
            can{" "}
            <a class="govuk-link" href="#">
              change your cookie settings
            </a>{" "}
            at any time.
          </p>
        ),
        actions: (
          <Button href="#">Hide this message</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, include all the cookie banner messages that the user might see, but hide these with the hidden HTML attribute.

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
  • shift focus to the confirmation message

Here’s an example:

<div
  class="govuk-cookie-banner"
  data-nosnippet="true"
  role="region"
  aria-label="Cookies on [name of service]"
>
  <div
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <h2
          class="govuk-cookie-banner__heading govuk-heading-m"
        >
          Cookies on [name of service]
        </h2>
        <div class="govuk-cookie-banner__content">
          <p class="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p class="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>
    <div class="govuk-button-group">
      <button
        data-module="govuk-button"
        name="cookies"
        class="govuk-button"
      >
        Accept analytics cookies
      </button>
      <button
        data-module="govuk-button"
        name="cookies"
        class="govuk-button"
      >
        Reject analytics cookies
      </button>
      <a
        class="govuk-link govuk-link--active"
        href="#"
      >
        View cookies
      </a>
    </div>
  </div>
  <div
    hidden=""
    role="alert"
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <div class="govuk-cookie-banner__content">
          <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>
        </div>
      </div>
    </div>
    <div class="govuk-button-group">
      <a
        data-module="govuk-button"
        draggable="false"
        role="button"
        class="govuk-button govuk-button--active"
        href="#"
      >
        Hide this message
      </a>
    </div>
  </div>
  <div
    hidden=""
    role="alert"
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <div class="govuk-cookie-banner__content">
          <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>
        </div>
      </div>
    </div>
    <div class="govuk-button-group">
      <a
        data-module="govuk-button"
        draggable="false"
        role="button"
        class="govuk-button govuk-button--active"
        href="#"
      >
        Hide this message
      </a>
    </div>
  </div>
</div>
<CookieBanner
  aria-label="Cookies on [name of service]"
  messages={[
    {
      heading: "Cookies on [name of service]",
      content: (
        <Fragment>
          <p className="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p className="govuk-body">
            We’d also like to use analytics cookies so
            we can understand how you use the service
            and make improvements.
          </p>
        </Fragment>
      ),
      actions: (
        <Fragment>
          <Button name="cookies">
            Accept analytics cookies
          </Button>
          <Button name="cookies">
            Reject analytics cookies
          </Button>
          <A href="#">View cookies</A>
        </Fragment>
      ),
    },
    {
      content: (
        <p className="govuk-body">
          You’ve accepted additional cookies. You can{" "}
          <a class="govuk-link" href="#">
            change your cookie settings
          </a>{" "}
          at any time.
        </p>
      ),
      actions: (
        <Button href="#">Hide this message</Button>
      ),
      hidden: true,
      role: "alert",
    },
    {
      content: (
        <p className="govuk-body">
          You’ve rejected additional cookies. You can{" "}
          <a class="govuk-link" href="#">
            change your cookie settings
          </a>{" "}
          at any time.
        </p>
      ),
      actions: (
        <Button href="#">Hide this message</Button>
      ),
      hidden: true,
      role: "alert",
    },
  ]}
/>

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.

<div
  class="govuk-cookie-banner"
  data-nosnippet="true"
  role="region"
  aria-label="Cookies on [name of service]"
>
  <div
    hidden=""
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <h2
          class="govuk-cookie-banner__heading govuk-heading-m"
        >
          Cookies on [name of service]
        </h2>
        <div class="govuk-cookie-banner__content">
          <p class="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p class="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>
    <div class="govuk-button-group">
      <button
        data-module="govuk-button"
        name="cookies"
        class="govuk-button"
      >
        Accept analytics cookies
      </button>
      <button
        data-module="govuk-button"
        name="cookies"
        class="govuk-button"
      >
        Reject analytics cookies
      </button>
      <a
        class="govuk-link govuk-link--active"
        href="#"
      >
        View cookies
      </a>
    </div>
  </div>
  <div
    role="alert"
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <div class="govuk-cookie-banner__content">
          <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>
        </div>
      </div>
    </div>
    <div class="govuk-button-group">
      <a
        data-module="govuk-button"
        draggable="false"
        role="button"
        class="govuk-button govuk-button--active"
        href="#"
      >
        Hide this message
      </a>
    </div>
  </div>
  <div
    hidden=""
    role="alert"
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <div class="govuk-cookie-banner__content">
          <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>
        </div>
      </div>
    </div>
    <div class="govuk-button-group">
      <a
        data-module="govuk-button"
        draggable="false"
        role="button"
        class="govuk-button govuk-button--active"
        href="#"
      >
        Hide this message
      </a>
    </div>
  </div>
</div>
<CookieBanner
  aria-label="Cookies on [name of service]"
  messages={[
    {
      heading: "Cookies on [name of service]",
      content: (
        <Fragment>
          <p className="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p className="govuk-body">
            We’d also like to use analytics cookies so
            we can understand how you use the service
            and make improvements.
          </p>
        </Fragment>
      ),
      actions: (
        <Fragment>
          <Button name="cookies">
            Accept analytics cookies
          </Button>
          <Button name="cookies">
            Reject analytics cookies
          </Button>
          <A href="#">View cookies</A>
        </Fragment>
      ),
      hidden: true,
    },
    {
      content: (
        <p className="govuk-body">
          You’ve accepted additional cookies. You can{" "}
          <a class="govuk-link" href="#">
            change your cookie settings
          </a>{" "}
          at any time.
        </p>
      ),
      actions: (
        <Button href="#">Hide this message</Button>
      ),
      role: "alert",
    },
    {
      content: (
        <p className="govuk-body">
          You’ve rejected additional cookies. You can{" "}
          <a class="govuk-link" href="#">
            change your cookie settings
          </a>{" "}
          at any time.
        </p>
      ),
      actions: (
        <Button href="#">Hide this message</Button>
      ),
      hidden: true,
      role: "alert",
    },
  ]}
/>

When the user has rejected cookies

<div
  class="govuk-cookie-banner"
  data-nosnippet="true"
  role="region"
  aria-label="Cookies on [name of service]"
>
  <div
    hidden=""
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <h2
          class="govuk-cookie-banner__heading govuk-heading-m"
        >
          Cookies on [name of service]
        </h2>
        <div class="govuk-cookie-banner__content">
          <p class="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p class="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>
    <div class="govuk-button-group">
      <button
        data-module="govuk-button"
        name="cookies"
        class="govuk-button"
      >
        Accept analytics cookies
      </button>
      <button
        data-module="govuk-button"
        name="cookies"
        class="govuk-button"
      >
        Reject analytics cookies
      </button>
      <a
        class="govuk-link govuk-link--active"
        href="#"
      >
        View cookies
      </a>
    </div>
  </div>
  <div
    hidden=""
    role="alert"
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <div class="govuk-cookie-banner__content">
          <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>
        </div>
      </div>
    </div>
    <div class="govuk-button-group">
      <a
        data-module="govuk-button"
        draggable="false"
        role="button"
        class="govuk-button govuk-button--active"
        href="#"
      >
        Hide this message
      </a>
    </div>
  </div>
  <div
    role="alert"
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <div class="govuk-cookie-banner__content">
          <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>
        </div>
      </div>
    </div>
    <div class="govuk-button-group">
      <a
        data-module="govuk-button"
        draggable="false"
        role="button"
        class="govuk-button govuk-button--active"
        href="#"
      >
        Hide this message
      </a>
    </div>
  </div>
</div>
<CookieBanner
  aria-label="Cookies on [name of service]"
  messages={[
    {
      heading: "Cookies on [name of service]",
      content: (
        <Fragment>
          <p className="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p className="govuk-body">
            We’d also like to use analytics cookies so
            we can understand how you use the service
            and make improvements.
          </p>
        </Fragment>
      ),
      actions: (
        <Fragment>
          <Button name="cookies">
            Accept analytics cookies
          </Button>
          <Button name="cookies">
            Reject analytics cookies
          </Button>
          <A href="#">View cookies</A>
        </Fragment>
      ),
      hidden: true,
    },
    {
      content: (
        <p className="govuk-body">
          You’ve accepted additional cookies. You can{" "}
          <a class="govuk-link" href="#">
            change your cookie settings
          </a>{" "}
          at any time.
        </p>
      ),
      actions: (
        <Button href="#">Hide this message</Button>
      ),
      hidden: true,
      role: "alert",
    },
    {
      content: (
        <p className="govuk-body">
          You’ve rejected additional cookies. You can{" "}
          <a class="govuk-link" href="#">
            change your cookie settings
          </a>{" "}
          at any time.
        </p>
      ),
      actions: (
        <Button href="#">Hide this message</Button>
      ),
      role: "alert",
    },
  ]}
/>

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’.

See the cookies page for more advice on writing about cookies.

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.

<div
  class="govuk-cookie-banner"
  data-nosnippet="true"
  role="region"
  aria-label="Cookies on [name of service]"
>
  <div
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <h2
          class="govuk-cookie-banner__heading govuk-heading-m"
        >
          Cookies on [name of service]
        </h2>
        <div class="govuk-cookie-banner__content">
          <p class="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p class="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>
    <div class="govuk-button-group">
      <button
        data-module="govuk-button"
        value="accept"
        name="cookies"
        class="govuk-button"
      >
        Accept analytics cookies
      </button>
      <button
        data-module="govuk-button"
        value="reject"
        name="cookies"
        class="govuk-button"
      >
        Reject analytics cookies
      </button>
      <a
        class="govuk-link govuk-link--active"
        href="#"
      >
        View cookies
      </a>
    </div>
  </div>
</div>
<CookieBanner
  aria-label="Cookies on [name of service]"
  messages={[
    {
      heading: "Cookies on [name of service]",
      content: (
        <Fragment>
          <p className="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p className="govuk-body">
            We’d also like to use analytics cookies so
            we can understand how you use the service
            and make improvements.
          </p>
        </Fragment>
      ),
      actions: (
        <Fragment>
          <Button value="accept" name="cookies">
            Accept analytics cookies
          </Button>
          <Button value="reject" name="cookies">
            Reject analytics cookies
          </Button>
          <A href="#">View cookies</A>
        </Fragment>
      ),
    },
  ]}
/>

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="govuk-cookie-banner"
  data-nosnippet="true"
  role="region"
  aria-label="Cookies on [name of service]"
>
  <div
    class="govuk-width-container govuk-cookie-banner__message"
  >
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <h2
          class="govuk-cookie-banner__heading govuk-heading-m"
        >
          Cookies on [name of service]
        </h2>
        <div class="govuk-cookie-banner__content">
          <p class="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p class="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>
    <div class="govuk-button-group">
      <button
        data-module="govuk-button"
        value="accept"
        name="cookies"
        class="govuk-button"
      >
        Accept additional cookies
      </button>
      <button
        data-module="govuk-button"
        value="reject"
        name="cookies"
        class="govuk-button"
      >
        Reject additional cookies
      </button>
      <a
        class="govuk-link govuk-link--active"
        href="#"
      >
        View cookies
      </a>
    </div>
  </div>
</div>
<CookieBanner
  aria-label="Cookies on [name of service]"
  messages={[
    {
      heading: "Cookies on [name of service]",
      content: (
        <Fragment>
          <p className="govuk-body">
            We use some essential cookies to make this
            service work.
          </p>
          <p className="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>
        </Fragment>
      ),
      actions: (
        <Fragment>
          <Button value="accept" name="cookies">
            Accept additional cookies
          </Button>
          <Button value="reject" name="cookies">
            Reject additional cookies
          </Button>
          <A href="#">View cookies</A>
        </Fragment>
      ),
    },
  ]}
/>

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.