Skip to content

Top cookie banner in HTML and CSS

A banner at the top of the page, in the document flow, that never hides content.

Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in HTML and CSS

consent.js
const STORAGE_KEY = "forge-consent";
// The CNIL recommends asking again after six months.
const MAX_AGE = 1000 * 60 * 60 * 24 * 182;

function readConsent() {
  try {
    const stored = JSON.parse(localStorage.getItem(STORAGE_KEY));
    return stored && Date.now() - Date.parse(stored.date) < MAX_AGE ? stored : null;
  } catch {
    return null;
  }
}
index.html
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Bandeau de cookies en haut de page</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <div data-consent-root>
        <section class="ckt" data-consent aria-labelledby="cookies-bandeau-haut-title">
style.css
:root {
  --ck-bg: #ffedd5;
  --ck-text: #2c1404;
  --ck-muted: #6b3a14;
  --ck-line: #fdba74;
  --ck-btn: #9a3412;
  --ck-btn-text: #ffffff;
  --ck-accent: #9a3412;
  --ck-ring: #7c2d12;
  --demo-bg: #fff8f1;
  --demo-text: #2c1404;
  --ck-radius: 999px;

Free component: copy it freely, including for commercial projects.

Cookie banners components in HTML and CSS
  • A rounded dark bar floating at the bottom of the screen, text on the left and buttons on the right on large screens.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An understated banner with square corners and a thick rule, suited to local authorities, firms and public institutions.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A floating card in the bottom-left corner, discreet yet always visible.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A full-width banner pinned to the bottom of the screen, with refuse, customize and accept on the same level.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component