Skip to content

Free tool · no sign-up

Free cookie banner generator

Pick a layout, colours and wording, try the banner in the live preview, and copy the code. It's plain HTML, CSS and JavaScript with no dependencies: Accept all, Reject all and Customize buttons, a remembered choice, script blocking until consent and optional Google Consent Mode v2 signals. Free, no sign-up.

#18181b

No cookie policy yet? Generate one free.

Cookie categories visitors can choose

Live preview (click the buttons to try it)

1. In <head>

First thing in <head>, before your Google tag

<!-- Google Consent Mode v2 defaults: paste first in <head>, before your Google tag. -->
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('consent', 'default', { ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', analytics_storage: 'denied', wait_for_update: 500 });
</script>

2. Before </body>

The banner, its styles and the consent script

<!-- Cookie consent banner: generated free at https://kiescy.com/tools/cookie-banner-generator -->
<!-- Paste just before </body>. -->
<style>
  #cc-banner{position:fixed;z-index:2147483000;left:16px;bottom:16px;max-width:400px;border-radius:16px;background:#ffffff;color:#18181b;padding:20px;box-shadow:0 10px 40px rgba(0,0,0,.18);border:1px solid #e4e4e7;font:14px/1.5 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;box-sizing:border-box}
  #cc-banner[hidden]{display:none}
  #cc-banner .cc-text{flex:1 1 320px}
  #cc-banner h2{margin:0 0 6px;font-size:16px}
  #cc-banner p{margin:0;color:#52525b}
  #cc-banner a{color:#18181b;text-decoration:underline}
  #cc-banner .cc-btns{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}
  #cc-banner button{cursor:pointer;font:inherit;font-weight:600;padding:9px 16px;border-radius:999px;border:1px solid #18181b;background:transparent;color:#18181b}
  #cc-banner button.cc-primary{background:#18181b;color:#fff}
  #cc-banner .cc-prefs{margin-top:14px;border-top:1px solid #e4e4e7;padding-top:10px}
  #cc-banner .cc-row{display:flex;justify-content:space-between;align-items:center;gap:16px;padding:8px 0;cursor:pointer}
  #cc-banner .cc-row small{color:#52525b}
  #cc-banner input{width:18px;height:18px;accent-color:#18181b;cursor:pointer}
</style>
<div id="cc-banner" role="dialog" aria-modal="false" aria-labelledby="cc-title" hidden>
  <div class="cc-text">
    <h2 id="cc-title">We value your privacy</h2>
    <p>We use cookies to run this site and, with your permission, to measure traffic and personalise ads. You can change your choice at any time. <a href="/cookie-policy">Cookie policy</a></p>
    <div class="cc-prefs" hidden>
      <label class="cc-row"><span><b>Strictly necessary</b><br><small>Needed for the site to work. Always on.</small></span><input type="checkbox" checked disabled></label>
      <label class="cc-row"><span><b>Analytics</b><br><small>Helps us understand how the site is used.</small></span><input type="checkbox" data-cat="analytics"></label>
      <label class="cc-row"><span><b>Marketing</b><br><small>Used to show and measure relevant ads.</small></span><input type="checkbox" data-cat="marketing"></label>
    </div>
  </div>
  <div class="cc-btns">
    <button type="button" class="cc-primary" data-cc-action="all">Accept all</button>
    <button type="button" data-cc-action="none">Reject all</button>
    <button type="button" data-cc-action="prefs">Customize</button>
    <button type="button" data-cc-action="save" hidden>Save choices</button>
  </div>
</div>
<script>
(function () {
  var NAME = 'cc_consent', DAYS = 180, CATS = ["analytics","marketing"];
  var el = document.getElementById('cc-banner'), memory = null;
  function load() {
    try { var m = document.cookie.match(new RegExp('(?:^|; )' + NAME + '=([^;]*)')); return m ? JSON.parse(decodeURIComponent(m[1])) : null; } catch (e) { return memory; }
  }
  function save(c) {
    memory = c;
    try { document.cookie = NAME + '=' + encodeURIComponent(JSON.stringify(c)) + ';max-age=' + DAYS * 86400 + ';path=/;SameSite=Lax' + (location.protocol === 'https:' ? ';Secure' : ''); } catch (e) {}
  }
  // Runs scripts written as <script type="text/plain" data-cc="analytics" ...> once that category is allowed.
  function unblock(c) {
    document.querySelectorAll('script[type="text/plain"][data-cc]').forEach(function (s) {
      if (!c[s.getAttribute('data-cc')]) return;
      var n = document.createElement('script');
      for (var i = 0; i < s.attributes.length; i++) { var a = s.attributes[i]; if (a.name !== 'type' && a.name !== 'data-cc') n.setAttribute(a.name, a.value); }
      n.text = s.text; s.parentNode.replaceChild(n, s);
    });
  }
  function apply(c) {
    if (typeof gtag === 'function') gtag('consent', 'update', {
      analytics_storage: c.analytics ? 'granted' : 'denied',
      ad_storage: c.marketing ? 'granted' : 'denied',
      ad_user_data: c.marketing ? 'granted' : 'denied',
      ad_personalization: c.marketing ? 'granted' : 'denied'
    });
    unblock(c);
    document.dispatchEvent(new CustomEvent('cc:consent', { detail: c }));
  }
  function choose(all) {
    var c = { v: 1, t: new Date().toISOString() };
    CATS.forEach(function (k) {
      var box = el.querySelector('input[data-cat="' + k + '"]');
      c[k] = all === true ? true : all === false ? false : !!(box && box.checked);
    });
    save(c); apply(c); el.hidden = true;
  }
  function open() {
    var c = load() || {};
    CATS.forEach(function (k) { var b = el.querySelector('input[data-cat="' + k + '"]'); if (b) b.checked = !!c[k]; });
    el.hidden = false;
  }
  el.addEventListener('click', function (e) {
    var a = e.target.closest('[data-cc-action]'); if (!a) return;
    var act = a.getAttribute('data-cc-action');
    if (act === 'all') choose(true);
    else if (act === 'none') choose(false);
    else if (act === 'save') choose(null);
    else if (act === 'prefs') { el.querySelector('.cc-prefs').hidden = false; a.hidden = true; el.querySelector('[data-cc-action="save"]').hidden = false; }
  });
  // Any element with data-cc-open (for example a "Cookie settings" footer link) reopens the banner.
  document.addEventListener('click', function (e) { if (e.target.closest('[data-cc-open]')) { e.preventDefault(); open(); } });
  window.ccConsent = { get: load, open: open };
  var saved = load();
  if (saved) apply(saved); else el.hidden = false;
})();
</script>

3. Block trackers until consent

Change each tracking script's type to text/plain and add the category. The banner runs it only after the visitor agrees:

<script type="text/plain" data-cc="analytics"
  src="https://www.googletagmanager.com/gtag/js?id=G-XXXX"></script>

Add data-cc-open to a footer link so visitors can change their mind.

Need proof of consent, auto-blocking and local laws?

This snippet doesn't keep consent records, scan for new cookies or change rules by country. Kiescy's banner does all three, with one script tag and a free plan.

Try the Kiescy banner free

Generated documents are a starting point based on common legal requirements, not legal advice. Check that every statement matches what your business really does, and ask a lawyer for high-risk processing.

How to install the banner

  1. Paste the Consent Mode block first in `<head>`, before your Google tag, so Google Analytics and Ads start with consent denied.
  2. Paste the banner block just before `</body>`.
  3. Mark trackers as blocked. Change each tracking script's type to text/plain and add data-cc="analytics" or data-cc="marketing". The banner runs them only after the visitor agrees.
  4. Add a way to change consent. Put data-cc-open on a "Cookie settings" link in your footer.
  5. Test it. Open your site in a private window, reject, and run the free privacy check to confirm nothing tracks you before consent.
Examples
<a href="#" data-cc-open>Cookie settings</a>

<!-- Meta Pixel, held until marketing consent -->
<script type="text/plain" data-cc="marketing">
  !function(f,b,e,v,n,t,s){ /* your pixel code */ }
</script>

What a compliant cookie banner needs

RequirementWhyThis generator
Reject as easy as AcceptEU regulators (CNIL, EDPB) and the UK ICO treat a missing or hidden Reject as invalid consent"Reject all" on the first layer
No non-essential cookies before consentConsent must come first (ePrivacy Art. 5(3))Blocks scripts marked text/plain
Granular choiceConsent must be specificOptional category toggles
No pre-ticked boxesPre-ticked boxes aren't consent (CJEU, Planet49)All categories start off
Easy to withdrawWithdrawing must be as easy as giving consent (GDPR Art. 7(3))data-cc-open reopens the banner
Google Consent Mode v2Required by Google for ads and measurement in the EEA and UKDefault denied, updated on choice
Proof of consentGDPR Art. 7(1): you must be able to show consent was givenNot included: needs a server (see below)

Read what is a cookie banner and Consent Mode v2 basic vs advanced for the details.

What a copy-paste banner can't do

This generator gives you a solid, honest banner. It's a good fit for a small site with a few known scripts. As a site grows, three gaps appear:

  • Consent records. Regulators can ask you to prove a visitor consented. That needs a log on a server, with a timestamp and the banner version shown.
  • New trackers. Every new plugin or tag must be found and marked by hand, or it runs before consent.
  • Different laws by country. EU visitors need opt-in, Californians need a "Do Not Sell or Share" link and Global Privacy Control support, India needs DPDP notices in local languages.

Kiescy's consent banner handles all three with one script tag: geo-based rules, a real-browser cookie scanner and consent logs. It has install guides for WordPress, Shopify, Webflow, Next.js and 30+ more platforms.

Questions

Is this cookie banner GDPR compliant?

It provides the mechanics regulators look for: Reject on the first layer, nothing pre-ticked, scripts blocked until consent and easy withdrawal. Whether your site is compliant depends on blocking every tracker correctly, and on keeping proof of consent, which a client-side snippet can't do.

Does it work with WordPress, Shopify and Webflow?

Yes, anywhere you can add custom code to the head and body. On WordPress use a header/footer code plugin; on Shopify edit theme.liquid; on Webflow use Project settings → Custom code.

Does it support Google Consent Mode v2?

Yes. With the option on, it sets all four signals (ad_storage, analytics_storage, ad_user_data, ad_personalization) to denied by default and updates them when the visitor chooses.

Does the banner set any cookies itself?

One first-party cookie, cc_consent, which stores the visitor's choice. It's strictly necessary and doesn't need consent.

Is it really free?

Yes. The code is yours to use on any site, with no account and no external requests.

Get compliant this afternoon, not this quarter.

Set up your policies, banner and request form in one place. Free while Kiescy is in early access.