Skip to the content

Cookie banner

A cookie consent banner, a small card of ink in a corner of the window, done properly.

Become a member to unlock the full effect today.

Join now

Already a member? Sign in

Documentation

  1. Copy to Webflow

    Add Geist and Geist Mono to your site's fonts (Site settings, Fonts, Google Fonts) before pasting: Webflow removes any font your site has not installed.

  2. Add custom CSS

    The look of the banner is the cookie-banner-* classes of the paste; the Embed holds what fixes it to the window, hides it and moves it. Paste it as a direct child of the page, with nothing above it that carries a transform or a filter, make it a Component and place it on every page. The block named "Page of the preview" is the demo around the banner: delete it on your site, and keep the banner and the Embed. The buttons and the switches are Link blocks, because Webflow has no button that holds layers; the script gives each the role and the keys of a button.
  3. Add custom JS

  4. Use it on your own elements

    Custom attributes
    Select the element on the canvas and open the Settings panel. Under Custom attributes, add a pair: the name on the left, the value on the right.
    Custom attributeWhat it does
    data-cookie-banner Marks the banner: the block that holds the words, the answers and the categories. It takes no value: leave the value field empty. The settings below go on the same element.
    data-cookie-banner-refuse On the button that refuses everything but the locked categories. It takes no value. Give it the same class as the one that accepts: the two answers must weigh the same. [ Required ]
    data-cookie-banner-accept On the button that accepts every category. It takes no value. [ Required ]
    data-cookie-banner-choose On what opens and folds back the categories. It takes no value. The engine writes aria-expanded on it. Without it, and without a panel, the banner has two answers and nothing else. [ Optional ]
    data-cookie-banner-panel On the box Choose opens: it holds one box, which holds the categories and the save button. It takes no value. The stylesheet folds it to no height until it is asked for. [ Optional ]
    data-cookie-banner-category="measurement" On the box of one category; the value is its name, yours to choose, and the name gated scripts refer to. Add or remove boxes freely: the engine reads the list. A category the stored choice has never seen asks everyone again. [ Optional ]
    data-cookie-banner-switch On the switch of a category, inside its box. It takes no value. The engine gives it role="switch" and aria-checked; the whole box answers a click. [ Optional ]
    data-cookie-banner-title On the name of a category: it names the switch for a screen reader. It takes no value. [ Optional ]
    data-cookie-banner-locked On a category that cannot be refused, the necessary one: its switch is on and stays there. It takes no value. [ Optional ]
    data-cookie-banner-google="analytics_storage" On a category: the Google Consent Mode signals it answers for, separated by spaces. Read only when gtag is on the page. [ Optional ]
    data-cookie-banner-save On the button that stores the switches as they are. It takes no value. [ Optional ]
    data-cookie-banner-knob On the knob inside a switch, so the stylesheet can move it. It takes no value. [ Optional ]
    data-cookie-banner-run="measurement" On a script of the page written type="text/plain": it only runs once the category named is allowed. Also on an iframe or an image that carries data-src in place of src. [ Optional ]
    data-cookie-banner-open On anything of the page, a footer link for one: a press opens the banner on its categories. It takes no value. Needed when the setting mark is none. [ Optional ]
    data-cookie-banner-state Written by the engine on the banner: open, wide once it is drawn out, choosing while the categories show, blank while the words are away. Never written by hand; the stylesheet reads it, and so can a rule of yours. [ Optional ]
    Settings
    Every setting is a custom attribute too, added the same way and on the same element. An attribute always wins over the defaults written in the code.
    AttributeDefaultWhat it is
    data-cookie-banner-accent #ffab1a The colour of the edge that draws the banner out and takes it back, of the line on the mark, of a switch that is on and of the plate that rises on a button. Options: any CSS colour. The other colours are the banner's own classes: the engine reads the ink from the background of the banner.
    data-cookie-banner-mark left The corner the banner goes back to, where the mark stays. Options: left, the bottom left corner, the banner held to the left; right, the bottom right; none, no mark at all, the banner goes to the left and is gone, and something of the page marked data-cookie-banner-open must open it again.
    data-cookie-banner-key cookie-banner The name the choice is stored under in localStorage. Options: any text. Two sites on one domain that must not share a choice take two names; two banners with one name share theirs.
    data-cookie-banner-version 1 The version of what is asked. A stored choice of another version is no choice. Options: any text. Change it when the categories or what they cover change, and everyone is asked again.
    data-cookie-banner-days 180 How long a choice is kept before the banner asks again, in days.
    data-cookie-banner-delay 600 The wait before the banner first comes in, in milliseconds, for someone who has not chosen.
    data-cookie-banner-travel 1.3 The time the edge takes to draw the banner out of its mark, or to take it back, in seconds: up then across, or across then down.
    data-cookie-banner-reload 1 What happens when a category whose scripts already ran is withdrawn. Options: 1 reloads the page, the only way to stop a script that runs; 0 leaves the page as it is, for a site that stops its own tags on cookiebanner:change.
    data-cookie-banner-label Cookie settings The name of the mark, read by a screen reader and written beside it when the edge moves out under the pointer; also the name of the banner when its markup gives none. Options: any text, in the language of the page.
    data-cookie-banner-shown Cookie choices are open. The sentence a screen reader is told when the banner comes in. Options: any text.
    data-cookie-banner-saved Your cookie choice is saved. The sentence a screen reader is told once a choice is stored. Options: any text.
    Gating your scripts
    The banner only holds back what you mark. In Site settings, Custom code, or in an Embed, write each tag that needs consent with type="text/plain" and data-cookie-banner-run set to the name of its category: the browser reads it as text until that category is allowed, then the script writes it again as a real one. A tag left as a normal script runs whatever the visitor answers. The two test scripts at the end of the pasted Embed are the preview's: replace them with yours, or delete them. It is the mechanism, not legal advice: the words, the categories and the policy link are yours to write.
    Custom attributeWhat it does
    type="text/plain" On the script: what keeps the browser from running it. Not a custom attribute: it is written in the tag itself. A module is written with data-type="module" beside it.
    data-cookie-banner-run="measurement" On the same script: the category that lets it through, one of the names of the banner's categories. A name the banner does not list is let through by Accept all only.
    data-src="https://..." On an iframe or an image marked data-cookie-banner-run, in place of src: the address it only loads once its category is allowed.

What it does

Cookie banner is a site utility component for Webflow and vanilla JavaScript, with no library. Also called cookie consent banner, cookie consent or gdpr cookie banner.

A cookie consent banner, a small card of ink in a corner of the window, done properly. It offers Accept all and Refuse all as two buttons of the same class, the same size and the same hover, and Choose, which opens the categories: the necessary one, always on, then the ones the site declares in plain markup, each with a real switch, coming up one after the other. It moves in three beats. A small square stands in the corner; an edge of the accent colour draws the card out of it, up then across, the content sitting still while the edge uncovers it; the words come up. Once the choice is made the words leave, the edge sweeps back and the card is the square again: the mark, with the edge on its side. Under the pointer or the keyboard the edge moves out and uncovers the name of the mark; pressed, it draws the banner out again, the switches as they were left. The choice is stored in localStorage with a version and a duration, so nobody who chose is asked again until one of them changes. And it is a real gate: a script of the page written type="text/plain" with the name of a category only runs once that category is allowed, an event is fired with the choice, a small API reads it, Google Consent Mode is updated when gtag is on the page, and withdrawing a category reloads the page so what ran stops. It is not a dialog: the page stays in reach, the focus is never trapped, a live region says what happened, reduced motion gets the banner and the mark with no travel, the phone gets a sheet with two equal answers side by side, and a page without JavaScript shows no banner and runs no gated script. No library. It is the mechanism, not legal advice: the words, the categories and the policy link are the site's own. Pattern type cookie banner, cookie consent, consent manager.

Updated

Questions

Paste the banner: a block marked data-cookie-banner with its words, two answers, three categories and one Embed that holds all the code. Make it a Component, place it on every page, write your own text and policy link, and the choice is stored in the visitor's browser, with no account and no outside script.

Write each tag that needs consent with type="text/plain" and data-cookie-banner-run="measurement", the value being the name of one of your categories. The browser reads it as text, and the engine writes it again as a real script once that category is allowed, at the choice or at the next page load. A script that is not marked is not held back.

Yes, when gtag is on the page. Each category names its signals in data-cookie-banner-google, analytics_storage for one, and the engine sends gtag('consent', 'update', ...) with granted or denied at each choice and at each load that finds one. The default, denied, is yours to set before the Google tag.

No banner is, alone. This one is the mechanism: nothing gated runs before a choice, Refuse all is as easy as Accept all, no switch is on in advance, and the choice can be changed from the mark in the corner. The text, the list of categories, the policy page and marking every script are yours, and it is not legal advice.

The choice is kept in localStorage for the number of days of the setting days, 180 by default. Change data-cookie-banner-version and every visitor is asked again; adding a category to the markup does it too. CookieBanner.reset() forgets the choice of the current visitor.