How to use the cookie consent banner generator
- Write the Banner text and set the Cookie policy URL (default
/cookie-policy; leave it empty to hide the link). - Change the Accept label and Decline label if you like, for example “Allow all” and “Reject all”.
- Choose a Position: Bottom bar, Top bar or Corner box.
- Pick the Background, Text and Button colours, and set a Storage key.
- Copy the Snippet (paste before </body>) or download
cookie-banner.html, and paste it just before the closing body tag of every page.
What it does and when to use it
Use it on a small site that needs a simple yes/no cookie choice without a third-party consent platform. The snippet has three parts: a <style> block, the banner markup (an ARIA region labelled “Cookie consent” with your text, policy link and two buttons), and a script. Decline is outlined and Accept is filled with your button colour; both use the same size and border.
It does not cover per-category choices (only all or nothing), blocking or deleting cookies, a settings panel, records of consent, or translations. You still need a cookie policy that explains what you set; the cookie policy generator writes one. Check the Accept button’s white text against your button colour with the color contrast checker.
How it works
The banner starts hidden. On page load the script reads localStorage under your storage key. If a choice is saved, it fires a cookieconsent event with that choice and keeps the banner hidden; if not, it shows the banner. A click on a button saves “accepted” or “declined”, hides the banner and fires the same event. Load non-essential scripts only in a listener that checks for “accepted”. The storage key keeps only letters, digits, _, . and -.
Worked examples
Defaults. The snippet contains <div class="cc-banner" id="cc-banner" role="region" aria-label="Cookie consent" hidden> and var KEY = "cookie-consent";, with a dark bar fixed to the bottom of the screen.
Corner box with custom labels. Position Corner box, Accept “Allow all”, Decline “Reject all”, storage key “my site consent!”. The CSS uses bottom:16px;left:16px;max-width:360px, the button reads <button type="button" class="cc-btn cc-decline" data-cc="declined">Reject all</button>, and the key is cleaned to var KEY = "mysiteconsent";.
Limits and tips
- Add your listener first. For returning visitors, the event fires as soon as the snippet runs, so register your
cookieconsentlistener in a script above the snippet. - Keep the buttons equal. The EDPB report says button colours and contrast must not be obviously misleading, and gives unreadable text on the alternative button as an example.
- Test both paths. Check in your browser’s developer tools that nothing non-essential loads before you click Accept, or after Decline.
- Laws differ by country. These sources cover the EU and UK.
Frequently asked questions
Does this banner make my site compliant?
Why does the banner have a Decline button on the first screen?
How do visitors change their mind?
Is saving the choice in localStorage itself a problem?
Sources
- Directive 2002/58/EC (ePrivacy Directive), Article 5(3) — EUR-Lex, Publications Office of the European Union, accessed 2026-10-07
- Report of the work undertaken by the Cookie Banner Taskforce (adopted 17 January 2023) — European Data Protection Board, accessed 2026-10-07
- Cookies and similar technologies (guide to PECR) — Information Commissioner's Office (UK), accessed 2026-10-07
How do we know nothing is uploaded? Test it yourself on the privacy proof page.