If you want a cookie consent popup on your site that meets compliance requirements and lets visitors choose to accept or decline, just drop the code below at the end of your template, right before the </body> tag:
<div id="cookie-consent-banner" class="cookie-banner">
<div class="cookie-content">
<p>We use cookies to improve your browsing experience. By continuing to use our website, you agree to our <a href="/privacy-policy" target="_blank">Cookie Policy</a>.</p>
<div class="cookie-buttons">
<button id="cookie-accept" class="cookie-btn accept">Accept</button>
<button id="cookie-decline" class="cookie-btn decline">Decline</button>
<button id="cookie-close" class="cookie-btn close">×</button>
</div>
</div>
</div>
<style>
.cookie-banner {position: fixed;bottom: 0;left: 0;width: 100%;background-color: #2c3e50;color: #fff;padding: 15px 0;z-index: 9999;box-shadow: 0 -2px 10px rgba(0,0,0,0.1);transform: translateY(100%);transition: transform 0.3s ease;}
.cookie-banner.show {transform: translateY(0);}
.cookie-content {max-width: 1200px;margin: 0 auto;padding: 0 20px;display: flex;flex-wrap: wrap;justify-content: space-between;align-items: center;gap: 15px;}
.cookie-content p {margin: 0;font-size: 14px;line-height: 1.5;}
.cookie-content a {color: #3498db;text-decoration: underline;}
.cookie-buttons {display: flex;gap: 10px;}
.cookie-btn {padding: 8px 20px;border: none;border-radius: 4px;cursor: pointer;font-size: 14px;transition: background-color 0.2s;}
.cookie-btn.accept {background-color: #27ae60;color: #fff;}
.cookie-btn.accept:hover {background-color: #219653;}
.cookie-btn.decline {background-color: #e74c3c;color: #fff;}
.cookie-btn.decline:hover {background-color: #c0392b;}
.cookie-btn.close {padding: 8px 12px;background-color: #7f8c8d;color: #fff;font-size: 16px;line-height: 1;}
.cookie-btn.close:hover {background-color: #6c7a7b;}
@media (max-width: 768px) {
.cookie-content {flex-direction: column;text-align: center;}
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
const banner = document.getElementById('cookie-consent-banner');
const acceptBtn = document.getElementById('cookie-accept');
const declineBtn = document.getElementById('cookie-decline');
const closeBtn = document.getElementById('cookie-close');
const cookieConsent = localStorage.getItem('cookieConsent');
if (!cookieConsent) {
setTimeout(() => {
banner.classList.add('show');
}, 500);
}
acceptBtn.addEventListener('click', function() {
localStorage.setItem('cookieConsent', 'accepted');
banner.classList.remove('show');
console.log('User accepted the cookie terms');
});
declineBtn.addEventListener('click', function() {
localStorage.setItem('cookieConsent', 'declined');
banner.classList.remove('show');
console.log('User declined the cookie terms');
});
closeBtn.addEventListener('click', function() {
banner.classList.remove('show');
console.log('User closed the cookie banner');
});
});
</script>Notes before you use it:
- Point the link in
<a href="/privacy-policy">at your site's actual cookie policy or privacy policy page. - Adjust the colors, fonts, and spacing in the CSS to match your site.
- If you need other languages, swap the text inside the banner (e.g. "We use cookies to enhance your browsing experience...").
A different look: a card floating in the bottom-left corner:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Floating Cookie Banner (Bottom Left)</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}
.cookie-consent-container {
position: fixed;
bottom: 24px;
left: 24px;
background: #ffffff;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
padding: 20px;
max-width: 420px;
width: calc(100% - 48px);
z-index: 999999;
border: 1px solid #f0f0f0;
}
.cookie-consent-header {
display: flex;
align-items: center;
margin-bottom: 12px;
}
.cookie-consent-icon {
width: 24px;
height: 24px;
margin-right: 10px;
color: #0066ff;
}
.cookie-consent-title {
font-size: 16px;
font-weight: 600;
color: #1a1a1a;
}
.cookie-consent-desc {
font-size: 14px;
line-height: 1.6;
color: #666666;
margin-bottom: 16px;
}
.cookie-consent-desc a {
color: #0066ff;
text-decoration: none;
}
.cookie-consent-desc a:hover {
text-decoration: underline;
}
.cookie-consent-actions {
display: flex;
justify-content: flex-end;
gap: 12px;
}
.cookie-btn {
padding: 8px 16px;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
border: none;
transition: all 0.2s ease;
}
.cookie-btn-accept {
background: #0066ff;
color: #ffffff;
}
.cookie-btn-accept:hover {
background: #0052cc;
}
.cookie-btn-settings {
background: #f5f5f5;
color: #1a1a1a;
}
.cookie-btn-settings:hover {
background: #e8e8e8;
}
/* Responsive layout for mobile */
@media (max-width: 480px) {
.cookie-consent-container {
bottom: 16px;
left: 16px;
width: calc(100% - 32px);
padding: 16px;
}
.cookie-consent-actions {
flex-wrap: wrap;
justify-content: center;
}
.cookie-btn {
flex: 1;
min-width: 120px;
}
}
</style>
</head>
<body>
<div id="cookieConsentModal" class="cookie-consent-container">
<div class="cookie-consent-header">
<svg class="cookie-consent-icon" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-1-13h2v6h-2zm0 8h2v2h-2z"/>
</svg>
<h3 class="cookie-consent-title">Cookie Notice</h3>
</div>
<p class="cookie-consent-desc">
We use cookies to improve your browsing experience -- serving personalized content, analyzing site traffic, and so on. By continuing to use this site, you agree to our use of cookies as described in our <a href="/privacy-policy" target="_blank">Privacy Policy</a>. You can manage your cookie preferences at any time through your browser settings.
</p>
<div class="cookie-consent-actions">
<button id="cookieSettingsBtn" class="cookie-btn cookie-btn-settings">Cookie Settings</button>
<button id="cookieAcceptBtn" class="cookie-btn cookie-btn-accept">Accept</button>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const modal = document.getElementById('cookieConsentModal');
const acceptBtn = document.getElementById('cookieAcceptBtn');
const settingsBtn = document.getElementById('cookieSettingsBtn');
const hasCookieConsent = localStorage.getItem('ztee_cookie_consent');
if (hasCookieConsent) {
modal.style.display = 'none';
}
acceptBtn.addEventListener('click', function() {
localStorage.setItem('ztee_cookie_consent', 'accepted');
modal.style.display = 'none';
});
settingsBtn.addEventListener('click', function() {
alert('Cookie settings panel (extend this as needed)');
});
window.addEventListener('click', function(e) {
if (e.target === modal) {
modal.style.display = 'none';
}
});
});
</script>
</body>
</html>
Comments No Comments