Home › Developer Tools › Cookie Consent Banner Generator

Cookie Consent Banner Generator

Design a cookie banner for your site: write the message, pick the position and colors, add Accept, Reject and Customize buttons, and copy one self-contained snippet with no external library. It remembers each visitor's choice and only runs the scripts they agree to.

Last updated:

Text
Buttons and categories
Design
Consent storage
Live preview

      
Advertisement
Advertisement

How to use the Cookie Consent Banner Generator

  1. Write the banner text and link to your privacy or cookie policy.
  2. Choose the buttons and categories you need: Reject all and Customize are recommended for GDPR.
  3. Pick a position and colors, and check the live preview and contrast badges.
  4. Set how the choice is stored (cookie or localStorage, number of days) and whether to send Google Consent Mode signals.
  5. Copy the code, paste it before </body>, and change non-essential scripts to type="text/plain" with a data-consent category so they wait for consent.

Cookie categories explained

CategoryTypical examplesConsent needed (EU/UK)?data-consent value
NecessarySession and login cookies, shopping cart, load balancing, security, the consent cookie itselfNo, but list them in your cookie policy(not blocked)
PreferencesLanguage, region, dark mode, recently viewed itemsYes, unless strictly needed for a feature the user asked forpreferences
AnalyticsGoogle Analytics, Matomo with cookies, Hotjar, Microsoft ClarityYes in most EU countries (some allow strictly anonymous, first-party measurement)analytics
MarketingGoogle Ads, Meta Pixel, TikTok Pixel, LinkedIn Insight, ad network and retargeting cookiesYesmarketing

Blocking a script until consent

Change the script's type to text/plain and add the category. The browser ignores it until the banner swaps it for a real script after consent:

BeforeAfter
<script src="https://example-analytics.com/a.js"></script><script type="text/plain" data-consent="analytics" src="https://example-analytics.com/a.js"></script>
<script>fbq('init', '123');</script><script type="text/plain" data-consent="marketing">fbq('init', '123');</script>

With Google tags you can instead keep the tag loading and use Consent Mode: the default block sets every signal to denied, and Google's tags then avoid setting analytics and ad cookies until the banner sends granted.

A compliant banner in practice

  • No pre-ticked boxes. Optional categories start unchecked; consent must be an active choice.
  • Equal choices. Accept and Reject on the first layer, same size, neither hidden.
  • Nothing before consent. Test with the browser's developer tools (Application > Cookies): after a fresh load, only necessary cookies should exist.
  • Easy to change. A permanent Cookie settings link that calls CookieConsent.open().
  • Explained. Link to a policy listing each cookie, its purpose and duration; the Privacy Policy Generator includes a cookie section.

Frequently asked questions

Do I need a cookie consent banner?

If visitors from the EU, EEA or UK use your site and you set non-essential cookies, such as analytics or advertising cookies, the ePrivacy rules and GDPR require prior, informed consent. In the US there is no general cookie consent law, but state privacy laws such as the CCPA require an opt-out of selling or sharing data for targeted ads, which a banner with a Reject button can provide.

Does this banner block cookies before consent?

It blocks the scripts you mark. Change a tracking script from <script> to <script type="text/plain" data-consent="analytics"> (or marketing, preferences) and the banner only runs it after the visitor agrees to that category. Scripts you do not mark run as usual, so mark every non-essential one.

What is Google Consent Mode v2?

Consent Mode is Google's API that tells Google tags whether a visitor consented to analytics and ad cookies, using four signals: analytics_storage, ad_storage, ad_user_data and ad_personalization. Since March 2024 Google requires it for advertisers using personalized ads with visitors in the EEA. With the option on, the code sets all signals to denied by default and updates them when the visitor chooses.

Where is the visitor's choice stored?

In a first-party cookie (or localStorage if you choose) on the visitor's own browser, as a small JSON value with the date and each category's yes/no. Nothing is sent to FreeToolCabin or any other server. The banner shows again when the stored choice expires after the number of days you set.

How long should consent be remembered?

There is no single legal limit, but many EU regulators consider asking again after about 6 to 13 months reasonable; the French regulator CNIL recommends 6 months. The default here is 180 days. If you add new cookie categories, change "version": 1 to 2 in the code so everyone is asked again.

Why should Reject be as visible as Accept?

European regulators and courts say refusing cookies must be as easy as accepting them. A banner with only an Accept button, or a Reject option hidden in a second layer, has been fined in several countries. The generator shows a warning when the Reject button is turned off.

How do visitors change their cookie choice later?

Add a Cookie settings link in your footer that calls CookieConsent.open(). It reopens the banner with the visitor's current choices, so they can withdraw consent as easily as they gave it, as GDPR requires.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

Privacy Policy GeneratorCreate a privacy policy for your website or app with CCPA, CalOPPA, COPPA and AdSense sections.Terms and Conditions GeneratorCreate terms of service for a website, store, SaaS or app, with payments and governing law.CSS Button GeneratorDesign CSS buttons with gradients, borders, shadows and hover and active states, then copy the code.Meta Tag GeneratorCreate SEO, Open Graph and X meta tags with live previews.Are Cookies Enabled TestCheck if cookies, localStorage and sessionStorage work in your browser, with fix steps.UTM Campaign URL BuilderAdd UTM tracking parameters to links and make a QR code.Robots.txt GeneratorBuild a robots.txt file with rules, sitemap lines and AI-bot blocking presets.Sitemap GeneratorTurn a list of URLs into a valid XML sitemap file.SERP Snippet PreviewPreview your title tag and meta description with pixel-accurate truncation on desktop and mobile.Hreflang Tag GeneratorCreate hreflang tags, sitemap entries and Link headers for every language and region, validated.Canonical Tag GeneratorNormalize URLs and create rel=canonical tags and HTTP headers, for one page or a whole list.Content Security Policy GeneratorBuild a CSP header or meta tag with nonces, hashes, presets and report-only mode.Meta Tag AnalyzerPaste page HTML to audit title, description, canonical, robots, Open Graph and hreflang tags.Robots.txt TesterTest whether a URL is allowed or blocked by robots.txt for Googlebot and other crawlers.Sitemap URL ExtractorExtract every URL from a sitemap.xml or sitemap index, validate it and export to CSV or TXT.FAQ Schema GeneratorTurn questions and answers into FAQPage JSON-LD markup with validation and a preview.Google Review Link GeneratorTurn a Google Place ID into a direct review link, QR code and printable review card.Keyword Suggestion ToolTurn one seed keyword into hundreds of Google and YouTube autocomplete keyword ideas.Local Business Schema GeneratorCreate LocalBusiness JSON-LD with address, geo, opening hours, holiday hours and sameAs links.Structured Data ValidatorCheck JSON-LD, microdata and RDFa against schema.org and Google rich result requirements.Breadcrumb Schema GeneratorBuild BreadcrumbList JSON-LD plus the matching HTML breadcrumb from names and URLs.Cookie Policy GeneratorCreate a cookie policy with a ready cookie table for Google Analytics, AdSense, Meta Pixel and more.Disclaimer GeneratorWrite a website disclaimer for affiliate, health, finance or blog sites, with short post notices.Keyword CombinerCombine up to 4 keyword lists into every combination in broad, phrase and exact match.Long Tail Keyword GeneratorTurn a seed keyword into long-tail keywords with best, how to, near me, year and for X modifiers.On-Page SEO CheckerPaste page HTML and a keyword to audit title, meta, headings, alt text and keyword use.App Privacy Policy GeneratorCreate a privacy policy for your iOS or Android app from its SDKs, permissions and data.URL Tracking RemoverStrip utm, fbclid, gclid and other tracking parameters from one link or hundreds at once.YouTube Keyword ToolFind YouTube search suggestions for a video topic with A-Z expansion and copy them as tags.
See all 28 SEO & Marketing Tools →