Cookie banner
Asks once whether the site may use cookies, remembers the answer, and lets the reader change their mind later. Scripts like analytics can wait until they say yes. The banner sits in a corner (or along the bottom) and never covers the page.
Cookie banner
Here the banners are shown in place (.cookie-banner-inline); on a real site they float in the bottom corner. See the real one on the landing example.
<div class="cookie-banner cookie-banner-inline" role="region" aria-label="Cookies">
<p class="cookie-title"><i class="mi mi-cookie" aria-hidden="true"></i> Cookies</p>
<p class="cookie-text">We use one cookie to keep you signed in, and others to see which pages people read. <a href="#">Privacy</a></p>
<div class="cookie-actions">
<button class="btn btn-sm btn-ghost" type="button" data-momo-consent="reject">Reject</button>
<button class="btn btn-sm" type="button" data-momo-dialog="cookie-settings">Settings</button>
<button class="btn btn-sm btn-brand" type="button" data-momo-consent="accept">Accept all</button>
</div>
</div>As a bar
.cookie-banner-bar: across the bottom, text on one side and buttons on the other.
<div class="cookie-banner cookie-banner-bar cookie-banner-inline" role="region" aria-label="Cookies (bar)">
<p class="cookie-text">We use cookies to understand how the site is used. You choose which ones. <a href="#">Privacy</a></p>
<div class="cookie-actions">
<button class="btn btn-sm btn-ghost" type="button" data-momo-consent="reject">Reject</button>
<button class="btn btn-sm" type="button" data-momo-dialog="cookie-settings">Settings</button>
<button class="btn btn-sm btn-brand" type="button" data-momo-consent="accept">Accept all</button>
</div>
</div>Settings
A normal dialog with one switch per kind of cookie, named consent with the kind as its value. A switch that is checked and disabled is always on (the ones the site needs to work).
<button class="btn" type="button" data-momo-dialog="cookie-settings"><i class="mi mi-settings" aria-hidden="true"></i> Cookie settings</button>
<button class="btn btn-ghost" type="button" onclick="Momo.consent.reset(); Momo.toast('Choice forgotten')">Forget my choice</button>
<dialog class="dialog dialog-sm" id="cookie-settings" aria-labelledby="cookie-settings-title">
<div class="dialog-header">
<h2 class="dialog-title" id="cookie-settings-title">Cookie settings</h2>
<button class="btn btn-icon btn-sm btn-ghost" type="button" data-momo-close aria-label="Close"><i class="mi mi-x" aria-hidden="true"></i></button>
</div>
<div class="dialog-body">
<ul class="consent-list">
<li class="consent-item"><b>Needed</b><p>Signing in and remembering this choice. Always on.</p><label class="switch"><input type="checkbox" name="consent" value="needed" checked disabled><span class="visually-hidden">Needed cookies</span></label></li>
<li class="consent-item"><b>Analytics</b><p>Counting visits so we know which pages help.</p><label class="switch"><input type="checkbox" name="consent" value="analytics"><span class="visually-hidden">Analytics cookies</span></label></li>
<li class="consent-item"><b>Marketing</b><p>Showing you our ads on other sites.</p><label class="switch"><input type="checkbox" name="consent" value="marketing"><span class="visually-hidden">Marketing cookies</span></label></li>
</ul>
</div>
<div class="dialog-footer">
<button class="btn btn-ghost" type="button" data-momo-consent="reject">Reject all</button>
<button class="btn btn-brand" type="button" data-momo-consent="save">Save choices</button>
</div>
</dialog>Wait for a yes
Put a script that sets cookies inside a <template data-momo-consent-for="analytics">. It stays switched off, and Momo adds it to the page the moment the reader allows that kind (and on every later visit).
<template data-momo-consent-for="analytics">
<script src="https://analytics.example.com/script.js" defer></script>
</template>
From your own script: Momo.consent.get('analytics') is true or false, and the momo:consent event fires on document whenever the choice changes.
On a page
<div class="cookie-banner" data-momo-consent-banner role="region" aria-label="Cookies">…</div>
<dialog class="dialog dialog-sm" id="cookie-settings">…</dialog>
…
<footer>… <button data-momo-consent-open="cookie-settings">Cookie settings</button> …</footer>
data-momo-consent-banner is what makes it hide once answered and stay hidden on later visits. A button with data-momo-consent-open opens the settings again (give it the dialog's id), or brings the banner back if left empty.
Classes and attributes
| Class / attribute | Does |
|---|---|
.cookie-banner | A card in the bottom corner (the start side; full width on a phone) |
.cookie-banner-bar | A bar across the bottom instead |
.cookie-title / .cookie-text / .cookie-actions | The parts |
.consent-list / .consent-item | The rows in the settings, each with a switch |
data-momo-consent="accept | reject | save" | On a button: allow all / only the needed ones / what the switches say |
data-momo-consent-banner | Hide this once answered |
data-momo-consent-open="id" | Open the settings again |
template[data-momo-consent-for="kind"] | Added to the page only when that kind is allowed |
The choice is kept in the reader's browser (local storage), not in a cookie. Momo only remembers the answer; what you need to ask, and how, depends on your country's rules.