Develop a modal popup for displaying newsletter subscriptions with animations using…
- User
Develop a modal popup for displaying newsletter subscriptions with animations using HTML, CSS, and JS.
Assistant
The user wants a modal popup for newsletter subscriptions with animations. Let me create something visually striking and modern, avoiding the generic template look.
Let me think about the design:
- Typography: I'll use a distinctive font - maybe "Space Grotesk" for headlines (technical/modern) and "DM Sans" for body text
- Color scheme: I'll go with a dark theme with a vibrant accent - maybe a coral/orange accent on deep charcoal
- Background: Layered with subtle gradients and maybe some geometric shapes or noise texture
- Animation:
- Modal entrance with scale + fade
- Staggered content reveal
- Input focus states
- Button hover interactions
- Success state animation
- Confetti or particle effect on success
- Interactions:
- Close on backdrop click
- Close on ESC key
- Form validation
- Success state transformation
Let me build this out with proper accessibility, reduced motion support, and meaningful interactions.
I'll create:
- A trigger button to open the modal
- The modal with animated entrance
- Email input with validation
- Success animation
- Smooth transitions throughout
Color variables:
- --bg: #0f0f12 (deep dark)
- --fg: #f5f5f7 (off-white)
- --muted: #6b6b7b (gray)
- --accent: #ff6b4a (coral/orange)
- --card: #1a1a1f (card background)
- --border: #2a2a32 (subtle border)
Newsletter Subscription Modal
A visually striking modal with smooth animations, form validation, and a celebratory success state. Features staggered entrance animations, micro-interactions, and respects reduced motion preferences.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Newsletter Subscription</title> <script src="https://cdn.tailwindcss.com"></script> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=DM+Sans:wght@400;500&display=swap" rel="stylesheet"> <style> :root { --bg: #0a0a0c; --bg-elevated: #111114; --fg: #f0f0f2; --muted: #6e6e7a; --accent: #ff5733; --accent-glow: rgba(255, 87, 51, 0.3); --card: #161619; --border: #252529; --success: #22c55e; } * { box-sizing: border-box; } body { font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--fg); min-height: 100vh; margin: 0; overflow-x: hidden; } .font-display { font-family: 'Space Grotesk', sans-serif; } /* Background pattern */ .bg-pattern { position: fixed; inset: 0; background-image: radial-gradient(circle at 20% 80%, rgba(255, 87, 51, 0.08) 0%, transparent 50%), radial-gradient(circle at 80% 20%, rgba(255, 87, 51, 0.05) 0%, transparent 40%), radial-gradient(circle at 50% 50%, rgba(255, 87, 51, 0.03) 0%, transparent 60%); pointer-events: none; } .grid-overlay { position: fixed; inset: 0; background-image: linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px); background-size: 60px 60px; pointer-events: none; } /* Modal Backdrop */ .modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.8); backdrop-filter: blur(8px); opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 1rem; } .modal-backdrop.active { opacity: 1; visibility: visible; } /* Modal Container */ .modal { background: var(--card); border: 1px solid var(--border); border-radius: 20px; width: 100%; max-width: 440px; position: relative; overflow: hidden; transform: scale(0.9) translateY(20px); opacity: 0; transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease; } .modal-backdrop.active .modal { transform: scale(1) translateY(0); opacity: 1; } /* Modal glow effect */ .modal::before { content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; background: radial-gradient(circle at 50% 0%, var(--accent-glow) 0%, transparent 50%); opacity: 0.5; pointer-events: none; } /* Close button */ .close-btn { position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border); color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; z-index: 10; } .close-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--fg); transform: rotate(90deg); } .close-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } /* Modal content animations */ .modal-content { padding: 3rem 2rem 2rem; position: relative; z-index: 1; } .animate-item { opacity: 0; transform: translateY(20px); } .modal-backdrop.active .animate-item { animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; } .modal-backdrop.active .animate-item:nth-child(1) { animation-delay: 0.1s; } .modal-backdrop.active .animate-item:nth-child(2) { animation-delay: 0.2s; } .modal-backdrop.active .animate-item:nth-child(3) { animation-delay: 0.3s; } .modal-backdrop.active .animate-item:nth-child(4) { animation-delay: 0.4s; } .modal-backdrop.active .animate-item:nth-child(5) { animation-delay: 0.5s; } @keyframes slideUp { to { opacity: 1; transform: translateY(0); } } /* Icon container */ .icon-container { width: 72px; height: 72px; border-radius: 20px; background: linear-gradient(135deg, var(--accent) 0%, #ff8a5c 100%); display: flex; align-items: center; justify-content: center; margin-bottom: 1.5rem; position: relative; } .icon-container::after { content: ''; position: absolute; inset: -4px; border-radius: 24px; background: linear-gradient(135deg, var(--accent) 0%, #ff8a5c 100%); opacity: 0.3; filter: blur(12px); z-index: -1; } .icon-container svg { width: 32px; height: 32px; color: white; } /* Input styling */ .input-wrapper { position: relative; margin-bottom: 1rem; } .email-input { width: 100%; padding: 1rem 1.25rem; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; color: var(--fg); font-size: 1rem; font-family: inherit; transition: all 0.2s ease; } .email-input::placeholder { color: var(--muted); } .email-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); } .email-input.error { border-color: #ef4444; animation: shake 0.4s ease; } @keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } } .error-message { position: absolute; bottom: -20px; left: 0; font-size: 0.75rem; color: #ef4444; opacity: 0; transition: opacity 0.2s ease; } .error-message.visible { opacity: 1; } /* Subscribe button */ .subscribe-btn { width: 100%; padding: 1rem 1.5rem; background: linear-gradient(135deg, var(--accent) 0%, #ff8a5c 100%); border: none; border-radius: 12px; color: white; font-size: 1rem; font-weight: 600; font-family: 'Space Grotesk', sans-serif; cursor: pointer; position: relative; overflow: hidden; transition: transform 0.2s ease, box-shadow 0.2s ease; } .subscribe-btn::before { content: ''; position: absolute; inset: 0; background: linear-gradient(135deg, #ff8a5c 0%, var(--accent) 100%); opacity: 0; transition: opacity 0.3s ease; } .subscribe-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 24px var(--accent-glow); } .subscribe-btn:hover::before { opacity: 1; } .subscribe-btn:active { transform: translateY(0); } .subscribe-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } .subscribe-btn span { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; gap: 0.5rem; } .subscribe-btn.loading span { opacity: 0; } .subscribe-btn .spinner { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; opacity: 0; } .subscribe-btn.loading .spinner { opacity: 1; } .spinner::after { content: ''; width: 20px; height: 20px; border: 2px solid rgba(255, 255, 255, 0.3); border-top-color: white; border-radius: 50%; animation: spin 0.8s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } } /* Success state */ .success-content { display: none; text-align: center; padding: 3rem 2rem; } .modal.success .modal-content { display: none; } .modal.success .success-content { display: block; } .success-icon { width: 80px; height: 80px; border-radius: 50%; background: linear-gradient(135deg, var(--success) 0%, #4ade80 100%); display: flex; align-items: center; justify-content: center; margin: 0 auto 1.5rem; position: relative; } .success-icon svg { width: 40px; height: 40px; color: white; stroke-dasharray: 50; stroke-dashoffset: 50; } .modal.success .success-icon svg { animation: checkmark 0.5s ease 0.2s forwards; } @keyframes checkmark { to { stroke-dashoffset: 0; } } .success-icon::after { content: ''; position: absolute; inset: -8px; border-radius: 50%; background: var(--success); opacity: 0; } .modal.success .success-icon::after { animation: pulse-ring 0.6s ease 0.3s; } @keyframes pulse-ring { 0% { opacity: 0.4; transform: scale(1); } 100% { opacity: 0; transform: scale(1.5); } } /* Particles */ .particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; } .particle { position: absolute; width: 8px; height: 8px; border-radius: 50%; opacity: 0; } .modal.success .particle { animation: particle-burst 0.8s ease forwards; } @keyframes particle-burst { 0% { opacity: 1; transform: translate(0, 0) scale(1); } 100% { opacity: 0; transform: var(--particle-end) scale(0); } } /* Trigger button */ .trigger-btn { padding: 1rem 2rem; background: var(--card); border: 1px solid var(--border); border-radius: 12px; color: var(--fg); font-size: 1rem; font-weight: 500; font-family: 'Space Grotesk', sans-serif; cursor: pointer; transition: all 0.3s ease; position: relative; overflow: hidden; } .trigger-btn::before { content: ''; position: absolute; inset: 0; background: linear-gradient(135deg, var(--accent-glow) 0%, transparent 50%); opacity: 0; transition: opacity 0.3s ease; } .trigger-btn:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); } .trigger-btn:hover::before { opacity: 1; } .trigger-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } .trigger-btn span { position: relative; z-index: 1; } /* Reduced motion */ @media (prefers-reduced-motion: reduce) { .modal, .animate-item, .close-btn, .subscribe-btn, .trigger-btn, .success-icon svg, .success-icon::after, .particle { animation: none !important; transition: opacity 0.2s ease !important; } .modal-backdrop.active .animate-item { opacity: 1; transform: none; } } </style> </head> <body> <div class="bg-pattern"></div> <div class="grid-overlay"></div> <main class="min-h-screen flex flex-col items-center justify-center p-6 relative z-10"> <div class="text-center max-w-lg"> <h1 class="font-display text-4xl md:text-5xl font-bold mb-4" style="color: var(--fg);"> Stay in the Loop </h1> <p class="text-lg mb-8" style="color: var(--muted);"> Get weekly insights on design, development, and creative technology delivered straight to your inbox. </p> <button class="trigger-btn" id="openModal" aria-haspopup="dialog"> <span>Subscribe to Newsletter</span> </button> </div> <div class="mt-16 flex items-center gap-8 text-sm" style="color: var(--muted);"> <div class="flex items-center gap-2"> <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/> </svg> <span>No spam</span> </div> <div class="flex items-center gap-2"> <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/> <path d="M7 11V7a5 5 0 0 1 10 0v4"/> </svg> <span>Unsubscribe anytime</span> </div> </div> </main> <!-- Modal Backdrop --> <div class="modal-backdrop" id="modalBackdrop" role="dialog" aria-modal="true" aria-labelledby="modalTitle"> <div class="modal" id="modal"> <!-- Particles --> <div class="particles" id="particles"></div> <!-- Close Button --> <button class="close-btn" id="closeModal" aria-label="Close modal"> <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <line x1="18" y1="6" x2="6" y2="18"/> <line x1="6" y1="6" x2="18" y2="18"/> </svg> </button> <!-- Form Content --> <div class="modal-content"> <div class="animate-item"> <div class="icon-container"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"> <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/> <polyline points="22,6 12,13 2,6"/> </svg> </div> </div> <h2 id="modalTitle" class="animate-item font-display text-2xl font-bold mb-2" style="color: var(--fg);"> Join our newsletter </h2> <p class="animate-item mb-6" style="color: var(--muted);"> Get weekly insights on design, development, and creative technology. </p> <form id="subscribeForm" class="animate-item"> <div class="input-wrapper"> <input type="email" class="email-input" id="emailInput" placeholder="Enter your email address" aria-describedby="emailError" required > <span class="error-message" id="emailError">Please enter a valid email address</span> </div> <button type="submit" class="subscribe-btn" id="subscribeBtn"> <span> Subscribe Now <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <line x1="5" y1="12" x2="19" y2="12"/> <polyline points="12 5 19 12 12 19"/> </svg> </span> <div class="spinner"></div> </button> </form> <p class="animate-item text-xs mt-4 text-center" style="color: var(--muted);"> By subscribing, you agree to our Privacy Policy and consent to receive updates. </p> </div> <!-- Success Content --> <div class="success-content"> <div class="success-icon"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"> <polyline points="20 6 9 17 4 12"/> </svg> </div> <h2 class="font-display text-2xl font-bold mb-2" style="color: var(--fg);"> You're subscribed! </h2> <p style="color: var(--muted);"> Thanks for joining. Check your inbox for a welcome email. </p> </div> </div> </div> <script> // DOM Elements const openModalBtn = document.getElementById('openModal'); const closeModalBtn = document.getElementById('closeModal'); const modalBackdrop = document.getElementById('modalBackdrop'); const modal = document.getElementById('modal'); const subscribeForm = document.getElementById('subscribeForm'); const emailInput = document.getElementById('emailInput'); const emailError = document.getElementById('emailError'); const subscribeBtn = document.getElementById('subscribeBtn'); const particlesContainer = document.getElementById('particles'); // Store last focused element let lastFocusedElement = null; // Open modal function openModal() { lastFocusedElement = document.activeElement; modalBackdrop.classList.add('active'); document.body.style.overflow = 'hidden'; // Reset form state modal.classList.remove('success'); emailInput.value = ''; emailInput.classList.remove('error'); emailError.classList.remove('visible'); subscribeBtn.classList.remove('loading'); // Focus first input after animation setTimeout(() => { emailInput.focus(); }, 400); } // Close modal function closeModal() { modalBackdrop.classList.remove('active'); document.body.style.overflow = ''; // Return focus to trigger if (lastFocusedElement) { lastFocusedElement.focus(); } } // Create particles function createParticles() { particlesContainer.innerHTML = ''; const colors = ['#ff5733', '#ff8a5c', '#22c55e', '#4ade80', '#fbbf24']; for (let i = 0; i < 12; i++) { const particle = document.createElement('div'); particle.className = 'particle'; const angle = (i / 12) * Math.PI * 2; const distance = 80 + Math.random() * 40; const endX = Math.cos(angle) * distance; const endY = Math.sin(angle) * distance; particle.style.cssText = ` left: 50%; top: 40%; background: ${colors[i % colors.length]}; --particle-end: translate(${endX}px, ${endY}px); animation-delay: ${i * 0.05}s; `; particlesContainer.appendChild(particle); } } // Validate email function isValidEmail(email) { return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); } // Handle form submission function handleSubmit(e) { e.preventDefault(); const email = emailInput.value.trim(); if (!isValidEmail(email)) { emailInput.classList.add('error'); emailError.classList.add('visible'); emailInput.focus(); return; } emailInput.classList.remove('error'); emailError.classList.remove('visible'); // Show loading state subscribeBtn.classList.add('loading'); // Simulate API call setTimeout(() => { subscribeBtn.classList.remove('loading'); createParticles(); modal.classList.add('success'); // Auto close after success setTimeout(() => { closeModal(); }, 3000); }, 1500); } // Event listeners openModalBtn.addEventListener('click', openModal); closeModalBtn.addEventListener('click', closeModal); subscribeForm.addEventListener('submit', handleSubmit); // Close on backdrop click modalBackdrop.addEventListener('click', (e) => { if (e.target === modalBackdrop) { closeModal(); } }); // Close on Escape key document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && modalBackdrop.classList.contains('active')) { closeModal(); } }); // Clear error on input emailInput.addEventListener('input', () => { if (emailInput.classList.contains('error')) { emailInput.classList.remove('error'); emailError.classList.remove('visible'); } }); // Trap focus within modal modal.addEventListener('keydown', (e) => { if (e.key !== 'Tab') return; const focusableElements = modal.querySelectorAll( 'button, input, [tabindex]:not([tabindex="-1"])' ); const firstElement = focusableElements[0]; const lastElement = focusableElements[focusableElements.length - 1]; if (e.shiftKey && document.activeElement === firstElement) { e.preventDefault(); lastElement.focus(); } else if (!e.shiftKey && document.activeElement === lastElement) { e.preventDefault(); firstElement.focus(); } }); </script> </body> </html>Key Features
Design Highlights
- Dark theme with warm coral accent (#ff5733) creating visual impact
- Layered background with gradient blobs and subtle grid overlay for depth
- Space Grotesk display font paired with DM Sans for a technical-yet-friendly feel
Animations
- Entrance animation - Modal scales up with a spring-like easing curve
- Staggered reveal - Each content element animates in sequence (0.1s delays)
- Success celebration - Checkmark draws itself with a pulse ring effect
- Particle burst - Colorful particles explode on successful subscription
- Micro-interactions - Button hover lifts, close button rotates, input focus glows
Interactions
- Click trigger button to open modal
- Close via X button, backdrop click, or Escape key
- Real-time email validation with shake animation on error
- Loading spinner during "submission"
- Auto-close after successful subscription
Accessibility
- Semantic ARIA attributes (
role="dialog",aria-modal,aria-labelledby) - Focus trapping within modal
- Focus returns to trigger element on close
- Keyboard navigation support
prefers-reduced-motionrespected - all animations disabled for users who prefer it- Visible focus states on all interactive elements
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.