Cookie Consent Generator

Position
Style
Categories (necessary always on)
Color preset
Preview
Paste before </body>
<!-- Microapp Cookie Consent Banner — paste before </body> -->
<style>
.mcc-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0; border-top-left-radius: 12px; border-top-right-radius: 12px;
  background: #0f172a;
  color: #f1f5f9;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  padding: 20px 24px;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.18);
  border: none;
  z-index: 2147483647;
  max-width: 100%;
  box-sizing: border-box;
}
.mcc-banner[hidden] { display: none !important; }
.mcc-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; max-width: 1100px; margin: 0 auto; }
.mcc-message { flex: 1 1 320px; margin: 0; }
.mcc-message a { color: inherit; text-decoration: underline; }
.mcc-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.mcc-btn {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  color: #fff;
  transition: filter 0.15s ease;
}
.mcc-btn:hover { filter: brightness(1.1); }
.mcc-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.mcc-btn--accept { background: #22c55e; }
.mcc-btn--reject { background: #475569; }
.mcc-btn--customize { background: transparent; color: inherit; text-decoration: underline; padding: 10px 8px; }
.mcc-panel { display: none; margin-top: 16px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.15); }
.mcc-banner.mcc-open .mcc-panel { display: block; }
.mcc-cat { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; }
.mcc-cat-name { font-weight: 600; }
.mcc-cat-desc { font-size: 13px; opacity: 0.8; margin: 2px 0 0; }
.mcc-switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.mcc-switch input { opacity: 0; width: 0; height: 0; }
.mcc-slider {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.2);
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.15s;
}
.mcc-slider::before {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}
.mcc-switch input:checked + .mcc-slider { background: #22c55e; }
.mcc-switch input:checked + .mcc-slider::before { transform: translateX(18px); }
.mcc-switch input:disabled + .mcc-slider { opacity: 0.6; cursor: not-allowed; }
@media (max-width: 540px) {
  .mcc-banner { padding: 16px; font-size: 13px; }
  .mcc-btn { flex: 1 1 auto; }
}
</style>

<div id="mcc-banner" class="mcc-banner" role="dialog" aria-live="polite" aria-label="Cookie consent" hidden>
  <div class="mcc-row">
    <p class="mcc-message">We use cookies to make this site work and to understand how it&#39;s used. Pick what you&#39;re comfortable with. <a href="/privacy">Learn more</a>.</p>
    <div class="mcc-actions">
      <button type="button" class="mcc-btn mcc-btn--customize" data-mcc="customize" aria-expanded="false" aria-controls="mcc-panel">Customize</button>
      <button type="button" class="mcc-btn mcc-btn--reject" data-mcc="reject">Reject all</button>
      <button type="button" class="mcc-btn mcc-btn--accept" data-mcc="accept">Accept all</button>
    </div>
  </div>
    <div class="mcc-panel" id="mcc-panel">
      <div class="mcc-cat">
        <div>
          <div class="mcc-cat-name">Necessary</div>
          <p class="mcc-cat-desc">Required for the site to work — session, security, load balancing. Can&#39;t be turned off.</p>
        </div>
        <label class="mcc-switch">
          <input type="checkbox" name="mcc-necessary" checked disabled aria-label="Necessary cookies">
          <span class="mcc-slider"></span>
        </label>
      </div>
      <div class="mcc-cat">
        <div>
          <div class="mcc-cat-name">Analytics</div>
          <p class="mcc-cat-desc">Helps us understand which pages get used and where things break.</p>
        </div>
        <label class="mcc-switch">
          <input type="checkbox" name="mcc-analytics" aria-label="Analytics cookies">
          <span class="mcc-slider"></span>
        </label>
      </div>
      <div class="mcc-cat">
        <div>
          <div class="mcc-cat-name">Marketing</div>
          <p class="mcc-cat-desc">Lets advertisers measure campaign performance and show you relevant ads.</p>
        </div>
        <label class="mcc-switch">
          <input type="checkbox" name="mcc-marketing" aria-label="Marketing cookies">
          <span class="mcc-slider"></span>
        </label>
      </div>
      <div class="mcc-actions" style="margin-top: 12px;">
        <button type="button" class="mcc-btn mcc-btn--accept" data-mcc="save">Save preferences</button>
      </div>
    </div>
</div>

<script>
(function () {
  var KEY = 'cookie-consent';
  var CATEGORIES = ["necessary","analytics","marketing"];
  var banner = document.getElementById('mcc-banner');
  if (!banner) return;

  function read() {
    try {
      var raw = localStorage.getItem(KEY);
      if (!raw) return null;
      var parsed = JSON.parse(raw);
      if (parsed && typeof parsed === 'object' && parsed.consent) return parsed;
      return null;
    } catch (e) { return null; }
  }

  function write(consent) {
    var payload = { consent: consent, timestamp: new Date().toISOString(), version: 1 };
    try { localStorage.setItem(KEY, JSON.stringify(payload)); } catch (e) {}
    return payload;
  }

  function dispatch(consent) {
    try {
      window.dispatchEvent(new CustomEvent('cookieconsentchange', { detail: consent }));
    } catch (e) {
      var ev = document.createEvent('CustomEvent');
      ev.initCustomEvent('cookieconsentchange', false, false, consent);
      window.dispatchEvent(ev);
    }
  }

  function hide() { banner.hidden = true; }

  function allOf(value) {
    var out = {};
    for (var i = 0; i < CATEGORIES.length; i++) out[CATEGORIES[i]] = value;
    out.necessary = true;
    return out;
  }

  function readToggles() {
    var out = { necessary: true };
    for (var i = 1; i < CATEGORIES.length; i++) {
      var el = banner.querySelector('input[name="mcc-' + CATEGORIES[i] + '"]');
      out[CATEGORIES[i]] = !!(el && el.checked);
    }
    return out;
  }

  function applyToggles(consent) {
    for (var i = 1; i < CATEGORIES.length; i++) {
      var el = banner.querySelector('input[name="mcc-' + CATEGORIES[i] + '"]');
      if (el) el.checked = !!consent[CATEGORIES[i]];
    }
  }

  function commit(consent) {
    write(consent);
    dispatch(consent);
    hide();
  }

  var existing = read();
  if (existing) {
    dispatch(existing.consent);
    return;
  }
  banner.hidden = false;

  var acceptBtn = banner.querySelector('[data-mcc="accept"]');
  var rejectBtn = banner.querySelector('[data-mcc="reject"]');
  var custBtn = banner.querySelector('[data-mcc="customize"]');
  var saveBtn = banner.querySelector('[data-mcc="save"]');

  if (acceptBtn) acceptBtn.addEventListener('click', function () { commit(allOf(true)); });
  if (rejectBtn) rejectBtn.addEventListener('click', function () { commit(allOf(false)); });
  if (custBtn) custBtn.addEventListener('click', function () {
    banner.classList.toggle('mcc-open');
    var open = banner.classList.contains('mcc-open');
    custBtn.setAttribute('aria-expanded', open ? 'true' : 'false');
  });
  if (saveBtn) saveBtn.addEventListener('click', function () { commit(readToggles()); });
  applyToggles(allOf(false));

  window.MicroappCookieConsent = {
    get: function () { var r = read(); return r ? r.consent : null; },
    reset: function () { try { localStorage.removeItem(KEY); } catch (e) {} banner.hidden = false; },
    set: function (consent) { commit(Object.assign(allOf(false), consent || {}, { necessary: true })); },
  };
})();
</script>

A cookie consent banner is the small bar that appears the first time a visitor lands on your site, asking what's okay to track. This tool builds one. You pick the position (top or bottom), the visual style (minimal, detailed, brutalist), which non-essential categories to expose (analytics, marketing, preferences — necessary is always on and can't be turned off), the colors, and the button labels. The output is one self-contained block of HTML, CSS, and JavaScript. Paste it before the closing </body> tag of any site — static HTML, WordPress, a templated server response, anything. When a visitor clicks Accept, Reject, or saves a custom selection, the banner writes their choice to localStorage and fires a `cookieconsentchange` CustomEvent. Your analytics or marketing scripts wait for that event before loading, so nothing tracks the visitor without permission.

Built by Bob QA by Ben Shipped

How to use

  1. 1

    Pick a position — top of the viewport, or bottom (most sites pick bottom).

  2. 2

    Pick a style — minimal (one sentence + two buttons), detailed (adds per-category toggles), or brutalist (hard edges, monospace).

  3. 3

    Choose which non-essential category toggles to show. Necessary cookies are always on; they're the ones that make the site work.

  4. 4

    Set the colors. Start from a preset (Dark + green, Light + blue, Cream + ink, Brutalist) and tweak from there.

  5. 5

    Edit the message, button labels, privacy policy URL, and the localStorage key the banner will write to.

  6. 6

    Click Copy. Paste the block before </body> on every page (or in your shared layout / template).

  7. 7

    Wire your analytics scripts to wait for the `cookieconsentchange` CustomEvent — `window.addEventListener('cookieconsentchange', (e) => { if (e.detail.analytics) loadGA(); })`. Until consent is granted, those scripts don't run.

Frequently asked questions

Ratings & Reviews

Rate this tool

Sign in to leave a written review.
Loading reviews…