Neumorphism Cookie Consent Banner
A modern cookie consent banner with soft neumorphism design, featuring subtle shadows and elegant depth effects
Responsive Design
Yes
Dark Mode Support
No
lines
822
Browser Compatibility
No
Live Preview
Interact with the component without leaving the page.
Neumorphism Cookie Consent Banner
A beautifully crafted cookie consent banner featuring neumorphism design principles with soft shadows, subtle depth, and elegant interactions. Perfect for modern websites seeking a clean, sophisticated appearance.
Features
- Neumorphism Design: Soft UI with subtle shadows and depth effects
- Elegant Interactions: Smooth hover effects and gentle animations
- Customizable Theme: Easy color and shadow customization
- Responsive Layout: Adapts beautifully to all screen sizes
- GDPR Compliant: Complete consent management with granular controls
- Accessibility First: Full keyboard navigation and screen reader support
- Smooth Animations: Gentle transitions that enhance user experience
- Local Storage: Persistent user preference management
Preview
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Neumorphism Cookie Banner</title>
<style>
:root {
--primary-bg: #e6e7ee;
--secondary-bg: #f0f0f3;
--text-primary: #4a4a4a;
--text-secondary: #6c6c6c;
--accent-color: #667eea;
--success-color: #48bb78;
--danger-color: #f56565;
--warning-color: #ed8936;
--shadow-light: #ffffff;
--shadow-dark: #d1d9e6;
--border-radius: 20px;
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #e6e7ee 0%, #f0f0f3 100%);
min-height: 100vh;
color: var(--text-primary);
line-height: 1.6;
}
.demo-content {
padding: 3rem 2rem;
text-align: center;
max-width: 800px;
margin: 0 auto;
}
.demo-content h1 {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 1rem;
background: linear-gradient(135deg, var(--accent-color), #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.demo-content p {
font-size: 1.1rem;
color: var(--text-secondary);
margin-bottom: 2rem;
}.neuro-cookie-banner {
position: fixed;
bottom: 2rem;
left: 2rem;
right: 2rem;
background: var(--primary-bg);
border-radius: var(--border-radius);
padding: 2rem;
box-shadow:
20px 20px 60px var(--shadow-dark),
-20px -20px 60px var(--shadow-light),
inset 0 0 0 1px rgba(255, 255, 255, 0.1);
transform: translateY(120%);
transition: var(--transition);
z-index: 10000;
max-width: 1200px;
margin: 0 auto;
}
.neuro-cookie-banner.show {
transform: translateY(0);
}
.cookie-container {
display: grid;
grid-template-columns: 1fr auto;
gap: 2rem;
align-items: center;
}
.cookie-info {
display: flex;
align-items: flex-start;
gap: 1rem;
}
.cookie-icon {
width: 48px;
height: 48px;
background: var(--secondary-bg);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
box-shadow:
8px 8px 16px var(--shadow-dark),
-8px -8px 16px var(--shadow-light);
flex-shrink: 0;
}
.cookie-text {
flex: 1;
}
.cookie-title {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 0.5rem;
color: var(--text-primary);
}
.cookie-description {
color: var(--text-secondary);
font-size: 0.95rem;
line-height: 1.5;
}
.cookie-link {
color: var(--accent-color);
text-decoration: none;
font-weight: 500;
transition: var(--transition);
}
.cookie-link:hover {
color: #5a67d8;
text-decoration: underline;
}
.cookie-actions {
display: flex;
gap: 1rem;
flex-wrap: wrap;
}.neuro-btn {
padding: 0.75rem 1.5rem;
border: none;
border-radius: 12px;
font-family: inherit;
font-size: 0.9rem;
font-weight: 600;
cursor: pointer;
transition: var(--transition);
position: relative;
overflow: hidden;
min-width: 120px;
background: var(--secondary-bg);
color: var(--text-primary);
}
.neuro-btn::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
transition: left 0.5s ease;
}
.neuro-btn:hover::before {
left: 100%;
}
.btn-primary {
background: var(--accent-color);
color: white;
box-shadow:
8px 8px 16px rgba(102, 126, 234, 0.3),
-8px -8px 16px rgba(255, 255, 255, 0.8),
inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow:
12px 12px 24px rgba(102, 126, 234, 0.4),
-12px -12px 24px rgba(255, 255, 255, 0.9),
inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}
.btn-primary:active {
transform: translateY(0);
box-shadow:
4px 4px 8px rgba(102, 126, 234, 0.3),
-4px -4px 8px rgba(255, 255, 255, 0.8),
inset 2px 2px 4px rgba(102, 126, 234, 0.2);
}
.btn-secondary {
box-shadow:
8px 8px 16px var(--shadow-dark),
-8px -8px 16px var(--shadow-light);
}
.btn-secondary:hover {
transform: translateY(-2px);
box-shadow:
12px 12px 24px var(--shadow-dark),
-12px -12px 24px var(--shadow-light);
}
.btn-secondary:active {
transform: translateY(0);
box-shadow:
inset 4px 4px 8px var(--shadow-dark),
inset -4px -4px 8px var(--shadow-light);
}
.btn-outline {
background: transparent;
border: 2px solid var(--accent-color);
color: var(--accent-color);
box-shadow:
4px 4px 8px var(--shadow-dark),
-4px -4px 8px var(--shadow-light);
}
.btn-outline:hover {
background: var(--accent-color);
color: white;
transform: translateY(-2px);
}.cookie-settings-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(230, 231, 238, 0.8);
backdrop-filter: blur(10px);
display: flex;
align-items: center;
justify-content: center;
z-index: 10001;
opacity: 0;
visibility: hidden;
transition: var(--transition);
}
.cookie-settings-modal.show {
opacity: 1;
visibility: visible;
}
.settings-content {
background: var(--primary-bg);
border-radius: var(--border-radius);
padding: 2rem;
max-width: 500px;
width: 90%;
max-height: 80vh;
overflow-y: auto;
box-shadow:
20px 20px 60px var(--shadow-dark),
-20px -20px 60px var(--shadow-light);
transform: scale(0.9);
transition: var(--transition);
}
.cookie-settings-modal.show .settings-content {
transform: scale(1);
}
.settings-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 2rem;
padding-bottom: 1rem;
border-bottom: 1px solid var(--shadow-dark);
}
.settings-title {
font-size: 1.5rem;
font-weight: 700;
color: var(--text-primary);
}
.close-btn {
width: 40px;
height: 40px;
border: none;
border-radius: 10px;
background: var(--secondary-bg);
color: var(--text-secondary);
font-size: 1.2rem;
cursor: pointer;
transition: var(--transition);
box-shadow:
6px 6px 12px var(--shadow-dark),
-6px -6px 12px var(--shadow-light);
}
.close-btn:hover {
color: var(--danger-color);
transform: scale(1.1);
}
.close-btn:active {
box-shadow:
inset 3px 3px 6px var(--shadow-dark),
inset -3px -3px 6px var(--shadow-light);
}
.cookie-category {
margin-bottom: 1.5rem;
padding: 1.5rem;
background: var(--secondary-bg);
border-radius: 16px;
box-shadow:
inset 8px 8px 16px var(--shadow-dark),
inset -8px -8px 16px var(--shadow-light);
}
.category-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.category-title {
font-weight: 600;
font-size: 1.1rem;
color: var(--text-primary);
}
.category-description {
font-size: 0.9rem;
color: var(--text-secondary);
line-height: 1.5;
}.neuro-toggle {
position: relative;
width: 60px;
height: 30px;
background: var(--secondary-bg);
border-radius: 15px;
cursor: pointer;
transition: var(--transition);
box-shadow:
inset 6px 6px 12px var(--shadow-dark),
inset -6px -6px 12px var(--shadow-light);
}
.neuro-toggle.active {
background: linear-gradient(135deg, var(--success-color), #38a169);
box-shadow:
inset 6px 6px 12px rgba(72, 187, 120, 0.3),
inset -6px -6px 12px rgba(255, 255, 255, 0.8);
}
.neuro-toggle::before {
content: '';
position: absolute;
top: 3px;
left: 3px;
width: 24px;
height: 24px;
background: var(--primary-bg);
border-radius: 50%;
transition: var(--transition);
box-shadow:
4px 4px 8px var(--shadow-dark),
-4px -4px 8px var(--shadow-light);
}
.neuro-toggle.active::before {
transform: translateX(30px);
background: white;
box-shadow:
4px 4px 8px rgba(72, 187, 120, 0.3),
-4px -4px 8px rgba(255, 255, 255, 0.9);
}
.settings-actions {
display: flex;
gap: 1rem;
justify-content: flex-end;
margin-top: 2rem;
padding-top: 1rem;
border-top: 1px solid var(--shadow-dark);
}@media (max-width: 768px) {
.neuro-cookie-banner {
bottom: 1rem;
left: 1rem;
right: 1rem;
padding: 1.5rem;
}
.cookie-container {
grid-template-columns: 1fr;
gap: 1.5rem;
text-align: center;
}
.cookie-info {
flex-direction: column;
text-align: center;
}
.cookie-actions {
justify-content: center;
}
.neuro-btn {
flex: 1;
min-width: auto;
}
.settings-content {
padding: 1.5rem;
margin: 1rem;
}
}
@media (max-width: 480px) {
.cookie-actions {
flex-direction: column;
}
.neuro-btn {
width: 100%;
}
}.demo-btn {
padding: 1rem 2rem;
border: none;
border-radius: 12px;
background: var(--accent-color);
color: white;
font-family: inherit;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: var(--transition);
box-shadow:
8px 8px 16px rgba(102, 126, 234, 0.3),
-8px -8px 16px rgba(255, 255, 255, 0.8);
}
.demo-btn:hover {
transform: translateY(-2px);
box-shadow:
12px 12px 24px rgba(102, 126, 234, 0.4),
-12px -12px 24px rgba(255, 255, 255, 0.9);
}
</style>
</head>
<body>
<div class="demo-content">
<h1>Neumorphism Cookie Banner</h1>
<p>Experience the elegant soft UI design with subtle shadows and smooth interactions</p>
<button class="demo-btn" onclick="showCookieBanner()">Show Cookie Banner</button>
</div>
<div id="neuroCookieBanner" class="neuro-cookie-banner">
<div class="cookie-container">
<div class="cookie-info">
<div class="cookie-icon">🍪</div>
<div class="cookie-text">
<div class="cookie-title">Cookie Preferences</div>
<div class="cookie-description">
We use cookies to enhance your browsing experience and provide personalized content.
<a href="#" class="cookie-link">Privacy Policy</a> |
<a href="#" class="cookie-link">Cookie Policy</a>
</div>
</div>
</div>
<div class="cookie-actions">
<button class="neuro-btn btn-primary" onclick="acceptCookies()">Accept All</button>
<button class="neuro-btn btn-secondary" onclick="declineCookies()">Decline</button>
<button class="neuro-btn btn-outline" onclick="openSettings()">Customize</button>
</div>
</div>
</div>
<div id="cookieSettingsModal" class="cookie-settings-modal">
<div class="settings-content">
<div class="settings-header">
<h3 class="settings-title">Cookie Settings</h3>
<button class="close-btn" onclick="closeSettings()">×</button>
</div>
<div class="cookie-category">
<div class="category-header">
<span class="category-title">Essential Cookies</span>
<div class="neuro-toggle active" data-category="essential">
</div>
</div>
<div class="category-description">
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you.
</div>
</div>
<div class="cookie-category">
<div class="category-header">
<span class="category-title">Analytics Cookies</span>
<div class="neuro-toggle" data-category="analytics">
</div>
</div>
<div class="category-description">
These cookies help us understand how visitors interact with our website by collecting and reporting information anonymously.
</div>
</div>
<div class="cookie-category">
<div class="category-header">
<span class="category-title">Marketing Cookies</span>
<div class="neuro-toggle" data-category="marketing">
</div>
</div>
<div class="category-description">
These cookies are used to deliver advertisements more relevant to you and your interests based on your browsing behavior.
</div>
</div>
<div class="cookie-category">
<div class="category-header">
<span class="category-title">Functional Cookies</span>
<div class="neuro-toggle" data-category="functional">
</div>
</div>
<div class="category-description">
These cookies enable enhanced functionality and personalization, such as remembering your preferences and settings.
</div>
</div>
<div class="settings-actions">
<button class="neuro-btn btn-secondary" onclick="saveSettings(false)">Save Preferences</button>
<button class="neuro-btn btn-primary" onclick="saveSettings(true)">Accept All</button>
</div>
</div>
</div>
<script>
class NeumorphismCookieBanner {
constructor(options = {}) {
this.options = {
autoShow: true,
showDelay: 1000,
storageKey: 'neuro_cookie_consent',
expiryDays: 365,
onAccept: null,
onDecline: null,
onSettingsSave: null,
...options
};
this.banner = document.getElementById('neuroCookieBanner');
this.modal = document.getElementById('cookieSettingsModal');
this.consent = this.getStoredConsent();
this.init();
}
init() {
if (this.options.autoShow && !this.consent) {
setTimeout(() => this.show(), this.options.showDelay);
}
this.setupEventListeners();
this.loadSettings();
}
setupEventListeners() {
document.querySelectorAll('.neuro-toggle').forEach(toggle => {
toggle.addEventListener('click', () => {
if (toggle.dataset.category !== 'essential') {
toggle.classList.toggle('active');
}
});
});
this.modal.addEventListener('click', (e) => {
if (e.target === this.modal) {
this.closeSettings();
}
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
this.closeSettings();
}
});
document.querySelectorAll('.neuro-btn').forEach(btn => {
btn.addEventListener('mouseenter', () => {
btn.style.transform = 'translateY(-2px)';
});
btn.addEventListener('mouseleave', () => {
btn.style.transform = 'translateY(0)';
});
});
}
show() {
this.banner.classList.add('show');
}
hide() {
this.banner.classList.remove('show');
}
accept() {
const consent = {
essential: true,
analytics: true,
marketing: true,
functional: true,
timestamp: Date.now()
};
this.saveConsent(consent);
this.hide();
if (this.options.onAccept) {
this.options.onAccept(consent);
}
}
decline() {
const consent = {
essential: true,
analytics: false,
marketing: false,
functional: false,
timestamp: Date.now()
};
this.saveConsent(consent);
this.hide();
if (this.options.onDecline) {
this.options.onDecline(consent);
}
}
openSettings() {
this.modal.classList.add('show');
document.body.style.overflow = 'hidden';
}
closeSettings() {
this.modal.classList.remove('show');
document.body.style.overflow = '';
}
saveSettings(acceptAll = false) {
const toggles = document.querySelectorAll('.neuro-toggle');
const consent = { timestamp: Date.now() };
toggles.forEach(toggle => {
const category = toggle.dataset.category;
if (acceptAll) {
consent[category] = true;
toggle.classList.add('active');
} else {
consent[category] = toggle.classList.contains('active');
}
});
this.saveConsent(consent);
this.closeSettings();
this.hide();
if (this.options.onSettingsSave) {
this.options.onSettingsSave(consent);
}
}
loadSettings() {
if (this.consent) {
document.querySelectorAll('.neuro-toggle').forEach(toggle => {
const category = toggle.dataset.category;
if (this.consent[category]) {
toggle.classList.add('active');
} else {
toggle.classList.remove('active');
}
});
}
}
saveConsent(consent) {
const expiryDate = new Date();
expiryDate.setDate(expiryDate.getDate() + this.options.expiryDays);
const consentData = {
...consent,
expiry: expiryDate.getTime()
};
localStorage.setItem(this.options.storageKey, JSON.stringify(consentData));
this.consent = consent;
}
getStoredConsent() {
try {
const stored = localStorage.getItem(this.options.storageKey);
if (stored) {
const data = JSON.parse(stored);
if (data.expiry && Date.now() < data.expiry) {
return data;
} else {
localStorage.removeItem(this.options.storageKey);
}
}
} catch (e) {
console.error('Error reading cookie consent:', e);
}
return null;
}
reset() {
localStorage.removeItem(this.options.storageKey);
this.consent = null;
this.show();
}
getConsent() {
return this.consent;
}
updateTheme(theme) {
const root = document.documentElement;
if (theme === 'dark') {
root.style.setProperty('--primary-bg', '#2d3748');
root.style.setProperty('--secondary-bg', '#4a5568');
root.style.setProperty('--text-primary', '#f7fafc');
root.style.setProperty('--text-secondary', '#e2e8f0');
root.style.setProperty('--shadow-light', '#4a5568');
root.style.setProperty('--shadow-dark', '#1a202c');
} else {
root.style.setProperty('--primary-bg', '#e6e7ee');
root.style.setProperty('--secondary-bg', '#f0f0f3');
root.style.setProperty('--text-primary', '#4a4a4a');
root.style.setProperty('--text-secondary', '#6c6c6c');
root.style.setProperty('--shadow-light', '#ffffff');
root.style.setProperty('--shadow-dark', '#d1d9e6');
}
}
}
const cookieBanner = new NeumorphismCookieBanner({
onAccept: (consent) => {
console.log('Cookies accepted:', consent);
},
onDecline: (consent) => {
console.log('Cookies declined:', consent);
},
onSettingsSave: (consent) => {
console.log('Settings saved:', consent);
}
});
function showCookieBanner() {
cookieBanner.reset();
}
function acceptCookies() {
cookieBanner.accept();
}
function declineCookies() {
cookieBanner.decline();
}
function openSettings() {
cookieBanner.openSettings();
}
function closeSettings() {
cookieBanner.closeSettings();
}
function saveSettings(acceptAll) {
cookieBanner.saveSettings(acceptAll);
}
</script>
</body>
</html>
Usage
Basic Implementation
const cookieBanner = new NeumorphismCookieBanner();
const cookieBanner = new NeumorphismCookieBanner({
autoShow: true,
showDelay: 2000,
storageKey: 'my_cookie_consent',
expiryDays: 180,
onAccept: (consent) => {
console.log('User accepted cookies:', consent);
if (consent.analytics) {
loadGoogleAnalytics();
}
if (consent.marketing) {
loadMarketingPixels();
}
},
onDecline: (consent) => {
console.log('User declined cookies:', consent);
},
onSettingsSave: (consent) => {
console.log('User saved custom settings:', consent);
}
});
Advanced Configuration
const advancedBanner = new NeumorphismCookieBanner({
autoShow: false, // Manual control
showDelay: 0,
storageKey: 'advanced_consent',
expiryDays: 90,
onAccept: (consent) => {
initializeAdvancedTracking(consent);
},
onDecline: (consent) => {
initializeEssentialOnly();
},
onSettingsSave: (consent) => {
loadScriptsBasedOnConsent(consent);
}
});
function switchTheme(theme) {
advancedBanner.updateTheme(theme);
}
function showConsentBanner() {
advancedBanner.show();
}
function checkConsentStatus() {
const consent = advancedBanner.getConsent();
if (consent) {
console.log('Current consent:', consent);
} else {
console.log('No consent given yet');
}
}
API Methods
Core Methods
show()- Display the cookie bannerhide()- Hide the cookie banneraccept()- Accept all cookies and hide bannerdecline()- Decline optional cookies and hide bannerreset()- Clear stored consent and show banner again
Settings Management
openSettings()- Open the settings modalcloseSettings()- Close the settings modalsaveSettings(acceptAll)- Save current settingsloadSettings()- Load and apply stored settings
Data Management
getConsent()- Get current consent objectsaveConsent(consent)- Save consent to storagegetStoredConsent()- Retrieve consent from storage
Theme Management
updateTheme(theme)- Switch between light and dark themes
Customization Options
Visual Customization
- Color Scheme: Modify CSS custom properties for different themes
- Shadow Intensity: Adjust shadow values for depth effect
- Border Radius: Customize roundness of elements
- Typography: Change font families and sizes
Functional Configuration
- Auto Display: Control automatic banner appearance
- Storage Duration: Set cookie consent expiry period
- Delay Settings: Configure show/hide timing
- Callback Functions: Custom handlers for user actions
Accessibility Features
- Keyboard Navigation: Full keyboard support with focus indicators
- Screen Reader Support: Proper ARIA labels and descriptions
- High Contrast: Enhanced visibility for accessibility
- Focus Management: Proper focus trapping in modal
Browser Compatibility
- Chrome 60+
- Firefox 55+
- Safari 12+
- Edge 79+
- Mobile browsers (iOS Safari 12+, Chrome Mobile 60+)
License
MIT License - feel free to use in personal and commercial projects.
HTML
794
lines
JavaScript
28
lines
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Neumorphism Cookie Banner</title>
<style>
:root {
--primary-bg: #e6e7ee;
--secondary-bg: #f0f0f3;
--text-primary: #4a4a4a;
--text-secondary: #6c6c6c;
--accent-color: #667eea;
--success-color: #48bb78;
--danger-color: #f56565;
--warning-color: #ed8936;
--shadow-light: #ffffff;
--shadow-dark: #d1d9e6;
--border-radius: 20px;
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #e6e7ee 0%, #f0f0f3 100%);
min-height: 100vh;
color: var(--text-primary);
line-height: 1.6;
}
.demo-content {
padding: 3rem 2rem;
text-align: center;
max-width: 800px;
margin: 0 auto;
}
.demo-content h1 {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 1rem;
background: linear-gradient(135deg, var(--accent-color), #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.demo-content p {
font-size: 1.1rem;
color: var(--text-secondary);
margin-bottom: 2rem;
}.neuro-cookie-banner {
position: fixed;
bottom: 2rem;
left: 2rem;
right: 2rem;
background: var(--primary-bg);
border-radius: var(--border-radius);
padding: 2rem;
box-shadow:
20px 20px 60px var(--shadow-dark),
-20px -20px 60px var(--shadow-light),
inset 0 0 0 1px rgba(255, 255, 255, 0.1);
transform: translateY(120%);
transition: var(--transition);
z-index: 10000;
max-width: 1200px;
margin: 0 auto;
}
.neuro-cookie-banner.show {
transform: translateY(0);
}
.cookie-container {
display: grid;
grid-template-columns: 1fr auto;
gap: 2rem;
align-items: center;
}
.cookie-info {
display: flex;
align-items: flex-start;
gap: 1rem;
}
.cookie-icon {
width: 48px;
height: 48px;
background: var(--secondary-bg);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
box-shadow:
8px 8px 16px var(--shadow-dark),
-8px -8px 16px var(--shadow-light);
flex-shrink: 0;
}
.cookie-text {
flex: 1;
}
.cookie-title {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 0.5rem;
color: var(--text-primary);
}
.cookie-description {
color: var(--text-secondary);
font-size: 0.95rem;
line-height: 1.5;
}
.cookie-link {
color: var(--accent-color);
text-decoration: none;
font-weight: 500;
transition: var(--transition);
}
.cookie-link:hover {
color: #5a67d8;
text-decoration: underline;
}
.cookie-actions {
display: flex;
gap: 1rem;
flex-wrap: wrap;
}.neuro-btn {
padding: 0.75rem 1.5rem;
border: none;
border-radius: 12px;
font-family: inherit;
font-size: 0.9rem;
font-weight: 600;
cursor: pointer;
transition: var(--transition);
position: relative;
overflow: hidden;
min-width: 120px;
background: var(--secondary-bg);
color: var(--text-primary);
}
.neuro-btn::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
transition: left 0.5s ease;
}
.neuro-btn:hover::before {
left: 100%;
}
.btn-primary {
background: var(--accent-color);
color: white;
box-shadow:
8px 8px 16px rgba(102, 126, 234, 0.3),
-8px -8px 16px rgba(255, 255, 255, 0.8),
inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow:
12px 12px 24px rgba(102, 126, 234, 0.4),
-12px -12px 24px rgba(255, 255, 255, 0.9),
inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}
.btn-primary:active {
transform: translateY(0);
box-shadow:
4px 4px 8px rgba(102, 126, 234, 0.3),
-4px -4px 8px rgba(255, 255, 255, 0.8),
inset 2px 2px 4px rgba(102, 126, 234, 0.2);
}
.btn-secondary {
box-shadow:
8px 8px 16px var(--shadow-dark),
-8px -8px 16px var(--shadow-light);
}
.btn-secondary:hover {
transform: translateY(-2px);
box-shadow:
12px 12px 24px var(--shadow-dark),
-12px -12px 24px var(--shadow-light);
}
.btn-secondary:active {
transform: translateY(0);
box-shadow:
inset 4px 4px 8px var(--shadow-dark),
inset -4px -4px 8px var(--shadow-light);
}
.btn-outline {
background: transparent;
border: 2px solid var(--accent-color);
color: var(--accent-color);
box-shadow:
4px 4px 8px var(--shadow-dark),
-4px -4px 8px var(--shadow-light);
}
.btn-outline:hover {
background: var(--accent-color);
color: white;
transform: translateY(-2px);
}.cookie-settings-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(230, 231, 238, 0.8);
backdrop-filter: blur(10px);
display: flex;
align-items: center;
justify-content: center;
z-index: 10001;
opacity: 0;
visibility: hidden;
transition: var(--transition);
}
.cookie-settings-modal.show {
opacity: 1;
visibility: visible;
}
.settings-content {
background: var(--primary-bg);
border-radius: var(--border-radius);
padding: 2rem;
max-width: 500px;
width: 90%;
max-height: 80vh;
overflow-y: auto;
box-shadow:
20px 20px 60px var(--shadow-dark),
-20px -20px 60px var(--shadow-light);
transform: scale(0.9);
transition: var(--transition);
}
.cookie-settings-modal.show .settings-content {
transform: scale(1);
}
.settings-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 2rem;
padding-bottom: 1rem;
border-bottom: 1px solid var(--shadow-dark);
}
.settings-title {
font-size: 1.5rem;
font-weight: 700;
color: var(--text-primary);
}
.close-btn {
width: 40px;
height: 40px;
border: none;
border-radius: 10px;
background: var(--secondary-bg);
color: var(--text-secondary);
font-size: 1.2rem;
cursor: pointer;
transition: var(--transition);
box-shadow:
6px 6px 12px var(--shadow-dark),
-6px -6px 12px var(--shadow-light);
}
.close-btn:hover {
color: var(--danger-color);
transform: scale(1.1);
}
.close-btn:active {
box-shadow:
inset 3px 3px 6px var(--shadow-dark),
inset -3px -3px 6px var(--shadow-light);
}
.cookie-category {
margin-bottom: 1.5rem;
padding: 1.5rem;
background: var(--secondary-bg);
border-radius: 16px;
box-shadow:
inset 8px 8px 16px var(--shadow-dark),
inset -8px -8px 16px var(--shadow-light);
}
.category-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.category-title {
font-weight: 600;
font-size: 1.1rem;
color: var(--text-primary);
}
.category-description {
font-size: 0.9rem;
color: var(--text-secondary);
line-height: 1.5;
}.neuro-toggle {
position: relative;
width: 60px;
height: 30px;
background: var(--secondary-bg);
border-radius: 15px;
cursor: pointer;
transition: var(--transition);
box-shadow:
inset 6px 6px 12px var(--shadow-dark),
inset -6px -6px 12px var(--shadow-light);
}
.neuro-toggle.active {
background: linear-gradient(135deg, var(--success-color), #38a169);
box-shadow:
inset 6px 6px 12px rgba(72, 187, 120, 0.3),
inset -6px -6px 12px rgba(255, 255, 255, 0.8);
}
.neuro-toggle::before {
content: '';
position: absolute;
top: 3px;
left: 3px;
width: 24px;
height: 24px;
background: var(--primary-bg);
border-radius: 50%;
transition: var(--transition);
box-shadow:
4px 4px 8px var(--shadow-dark),
-4px -4px 8px var(--shadow-light);
}
.neuro-toggle.active::before {
transform: translateX(30px);
background: white;
box-shadow:
4px 4px 8px rgba(72, 187, 120, 0.3),
-4px -4px 8px rgba(255, 255, 255, 0.9);
}
.settings-actions {
display: flex;
gap: 1rem;
justify-content: flex-end;
margin-top: 2rem;
padding-top: 1rem;
border-top: 1px solid var(--shadow-dark);
}@media (max-width: 768px) {
.neuro-cookie-banner {
bottom: 1rem;
left: 1rem;
right: 1rem;
padding: 1.5rem;
}
.cookie-container {
grid-template-columns: 1fr;
gap: 1.5rem;
text-align: center;
}
.cookie-info {
flex-direction: column;
text-align: center;
}
.cookie-actions {
justify-content: center;
}
.neuro-btn {
flex: 1;
min-width: auto;
}
.settings-content {
padding: 1.5rem;
margin: 1rem;
}
}
@media (max-width: 480px) {
.cookie-actions {
flex-direction: column;
}
.neuro-btn {
width: 100%;
}
}.demo-btn {
padding: 1rem 2rem;
border: none;
border-radius: 12px;
background: var(--accent-color);
color: white;
font-family: inherit;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: var(--transition);
box-shadow:
8px 8px 16px rgba(102, 126, 234, 0.3),
-8px -8px 16px rgba(255, 255, 255, 0.8);
}
.demo-btn:hover {
transform: translateY(-2px);
box-shadow:
12px 12px 24px rgba(102, 126, 234, 0.4),
-12px -12px 24px rgba(255, 255, 255, 0.9);
}
</style>
</head>
<body>
<div class="demo-content">
<h1>Neumorphism Cookie Banner</h1>
<p>Experience the elegant soft UI design with subtle shadows and smooth interactions</p>
<button class="demo-btn" onclick="showCookieBanner()">Show Cookie Banner</button>
</div>
<div id="neuroCookieBanner" class="neuro-cookie-banner">
<div class="cookie-container">
<div class="cookie-info">
<div class="cookie-icon">🍪</div>
<div class="cookie-text">
<div class="cookie-title">Cookie Preferences</div>
<div class="cookie-description">
We use cookies to enhance your browsing experience and provide personalized content.
<a href="#" class="cookie-link">Privacy Policy</a> |
<a href="#" class="cookie-link">Cookie Policy</a>
</div>
</div>
</div>
<div class="cookie-actions">
<button class="neuro-btn btn-primary" onclick="acceptCookies()">Accept All</button>
<button class="neuro-btn btn-secondary" onclick="declineCookies()">Decline</button>
<button class="neuro-btn btn-outline" onclick="openSettings()">Customize</button>
</div>
</div>
</div>
<div id="cookieSettingsModal" class="cookie-settings-modal">
<div class="settings-content">
<div class="settings-header">
<h3 class="settings-title">Cookie Settings</h3>
<button class="close-btn" onclick="closeSettings()">×</button>
</div>
<div class="cookie-category">
<div class="category-header">
<span class="category-title">Essential Cookies</span>
<div class="neuro-toggle active" data-category="essential">
</div>
</div>
<div class="category-description">
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you.
</div>
</div>
<div class="cookie-category">
<div class="category-header">
<span class="category-title">Analytics Cookies</span>
<div class="neuro-toggle" data-category="analytics">
</div>
</div>
<div class="category-description">
These cookies help us understand how visitors interact with our website by collecting and reporting information anonymously.
</div>
</div>
<div class="cookie-category">
<div class="category-header">
<span class="category-title">Marketing Cookies</span>
<div class="neuro-toggle" data-category="marketing">
</div>
</div>
<div class="category-description">
These cookies are used to deliver advertisements more relevant to you and your interests based on your browsing behavior.
</div>
</div>
<div class="cookie-category">
<div class="category-header">
<span class="category-title">Functional Cookies</span>
<div class="neuro-toggle" data-category="functional">
</div>
</div>
<div class="category-description">
These cookies enable enhanced functionality and personalization, such as remembering your preferences and settings.
</div>
</div>
<div class="settings-actions">
<button class="neuro-btn btn-secondary" onclick="saveSettings(false)">Save Preferences</button>
<button class="neuro-btn btn-primary" onclick="saveSettings(true)">Accept All</button>
</div>
</div>
</div>
<script>
class NeumorphismCookieBanner {
constructor(options = {}) {
this.options = {
autoShow: true,
showDelay: 1000,
storageKey: 'neuro_cookie_consent',
expiryDays: 365,
onAccept: null,
onDecline: null,
onSettingsSave: null,
...options
};
this.banner = document.getElementById('neuroCookieBanner');
this.modal = document.getElementById('cookieSettingsModal');
this.consent = this.getStoredConsent();
this.init();
}
init() {
if (this.options.autoShow && !this.consent) {
setTimeout(() => this.show(), this.options.showDelay);
}
this.setupEventListeners();
this.loadSettings();
}
setupEventListeners() {
document.querySelectorAll('.neuro-toggle').forEach(toggle => {
toggle.addEventListener('click', () => {
if (toggle.dataset.category !== 'essential') {
toggle.classList.toggle('active');
}
});
});
this.modal.addEventListener('click', (e) => {
if (e.target === this.modal) {
this.closeSettings();
}
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
this.closeSettings();
}
});
document.querySelectorAll('.neuro-btn').forEach(btn => {
btn.addEventListener('mouseenter', () => {
btn.style.transform = 'translateY(-2px)';
});
btn.addEventListener('mouseleave', () => {
btn.style.transform = 'translateY(0)';
});
});
}
show() {
this.banner.classList.add('show');
}
hide() {
this.banner.classList.remove('show');
}
accept() {
const consent = {
essential: true,
analytics: true,
marketing: true,
functional: true,
timestamp: Date.now()
};
this.saveConsent(consent);
this.hide();
if (this.options.onAccept) {
this.options.onAccept(consent);
}
}
decline() {
const consent = {
essential: true,
analytics: false,
marketing: false,
functional: false,
timestamp: Date.now()
};
this.saveConsent(consent);
this.hide();
if (this.options.onDecline) {
this.options.onDecline(consent);
}
}
openSettings() {
this.modal.classList.add('show');
document.body.style.overflow = 'hidden';
}
closeSettings() {
this.modal.classList.remove('show');
document.body.style.overflow = '';
}
saveSettings(acceptAll = false) {
const toggles = document.querySelectorAll('.neuro-toggle');
const consent = { timestamp: Date.now() };
toggles.forEach(toggle => {
const category = toggle.dataset.category;
if (acceptAll) {
consent[category] = true;
toggle.classList.add('active');
} else {
consent[category] = toggle.classList.contains('active');
}
});
this.saveConsent(consent);
this.closeSettings();
this.hide();
if (this.options.onSettingsSave) {
this.options.onSettingsSave(consent);
}
}
loadSettings() {
if (this.consent) {
document.querySelectorAll('.neuro-toggle').forEach(toggle => {
const category = toggle.dataset.category;
if (this.consent[category]) {
toggle.classList.add('active');
} else {
toggle.classList.remove('active');
}
});
}
}
saveConsent(consent) {
const expiryDate = new Date();
expiryDate.setDate(expiryDate.getDate() + this.options.expiryDays);
const consentData = {
...consent,
expiry: expiryDate.getTime()
};
localStorage.setItem(this.options.storageKey, JSON.stringify(consentData));
this.consent = consent;
}
getStoredConsent() {
try {
const stored = localStorage.getItem(this.options.storageKey);
if (stored) {
const data = JSON.parse(stored);
if (data.expiry && Date.now() < data.expiry) {
return data;
} else {
localStorage.removeItem(this.options.storageKey);
}
}
} catch (e) {
console.error('Error reading cookie consent:', e);
}
return null;
}
reset() {
localStorage.removeItem(this.options.storageKey);
this.consent = null;
this.show();
}
getConsent() {
return this.consent;
}
updateTheme(theme) {
const root = document.documentElement;
if (theme === 'dark') {
root.style.setProperty('--primary-bg', '#2d3748');
root.style.setProperty('--secondary-bg', '#4a5568');
root.style.setProperty('--text-primary', '#f7fafc');
root.style.setProperty('--text-secondary', '#e2e8f0');
root.style.setProperty('--shadow-light', '#4a5568');
root.style.setProperty('--shadow-dark', '#1a202c');
} else {
root.style.setProperty('--primary-bg', '#e6e7ee');
root.style.setProperty('--secondary-bg', '#f0f0f3');
root.style.setProperty('--text-primary', '#4a4a4a');
root.style.setProperty('--text-secondary', '#6c6c6c');
root.style.setProperty('--shadow-light', '#ffffff');
root.style.setProperty('--shadow-dark', '#d1d9e6');
}
}
}
const cookieBanner = new NeumorphismCookieBanner({
onAccept: (consent) => {
console.log('Cookies accepted:', consent);
},
onDecline: (consent) => {
console.log('Cookies declined:', consent);
},
onSettingsSave: (consent) => {
console.log('Settings saved:', consent);
}
});
function showCookieBanner() {
cookieBanner.reset();
}
function acceptCookies() {
cookieBanner.accept();
}
function declineCookies() {
cookieBanner.decline();
}
function openSettings() {
cookieBanner.openSettings();
}
function closeSettings() {
cookieBanner.closeSettings();
}
function saveSettings(acceptAll) {
cookieBanner.saveSettings(acceptAll);
}
</script>
</body>
</html>