Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
<!DOCTYPE html> <title>My Example</title> <!-- Place the following CSS in your <head> or stylesheet --> <style> /* This is an optional body style to provide a background for the page */ body { background-color: #f3f4f6; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif; } /* Optional: a container to center the card on the page for demonstration */ .demo-container-countdown { display: flex; justify-content: center; padding: 2rem; } /* === Countdown Timer Card Styles === */ .countdown-card { --countdown-radius: 16px; --countdown-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1); background: #ffffff; border-radius: var(--countdown-radius); box-shadow: var(--countdown-shadow); max-width: 500px; width: 100%; text-align: center; padding: 2rem 2.5rem; } .countdown-card-title { font-size: 1.5rem; font-weight: 700; margin-top: 0; margin-bottom: 0.5rem; color: #111827; } .countdown-card-subtitle { font-size: 1rem; color: #6b7280; margin: 0 0 2rem 0; } /* Container for the timer segments */ .countdown-timer-container { display: flex; justify-content: center; gap: 1rem; } .countdown-segment { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 70px; } .countdown-number { display: block; background-color: #f3f4f6; color: #1f2937; font-size: 2.25rem; font-weight: 700; line-height: 1; padding: 1rem 0.5rem; border-radius: 8px; width: 100%; margin-bottom: 0.5rem; } .countdown-label { font-size: 0.8rem; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; } </style> <!-- Place the following HTML in your <body> --> <div class="demo-container-countdown"> <!-- To set the date, change the `data-target-date` attribute below. --> <!-- The format should be a valid ISO 8601 string, e.g., "YYYY-MM-DDTHH:MM:SS" --> <div class="countdown-card" data-target-date="2050-12-30T00:00:00"> <h3 class="countdown-card-title">Launching Soon</h3> <p class="countdown-card-subtitle">Our new platform will be live in:</p> <div class="countdown-timer-container"> <div class="countdown-segment"> <span class="countdown-number" data-unit="days">00</span> <span class="countdown-label">Days</span> </div> <div class="countdown-segment"> <span class="countdown-number" data-unit="hours">00</span> <span class="countdown-label">Hours</span> </div> <div class="countdown-segment"> <span class="countdown-number" data-unit="minutes">00</span> <span class="countdown-label">Minutes</span> </div> <div class="countdown-segment"> <span class="countdown-number" data-unit="seconds">00</span> <span class="countdown-label">Seconds</span> </div> </div> </div> </div> <!-- Place the following JavaScript before your closing </body> tag --> <script> document.addEventListener('DOMContentLoaded', () => { const allCountdownCards = document.querySelectorAll('.countdown-card[data-target-date]'); allCountdownCards.forEach(card => { const targetDate = new Date(card.dataset.targetDate).getTime(); const updateCountdown = () => { const now = new Date().getTime(); const difference = targetDate - now; if (difference < 0) { clearInterval(interval); // Optional: Update UI when countdown ends card.querySelector('.countdown-card-subtitle').textContent = "Our new platform is live!"; card.querySelectorAll('.countdown-number').forEach(num => num.textContent = '00'); return; } const days = Math.floor(difference / (1000 * 60 * 60 * 24)); const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((difference % (1000 * 60)) / 1000); // Using `dataset.unit` to update the correct element card.querySelector('[data-unit="days"]').textContent = String(days).padStart(2, '0'); card.querySelector('[data-unit="hours"]').textContent = String(hours).padStart(2, '0'); card.querySelector('[data-unit="minutes"]').textContent = String(minutes).padStart(2, '0'); card.querySelector('[data-unit="seconds"]').textContent = String(seconds).padStart(2, '0'); }; const interval = setInterval(updateCountdown, 1000); updateCountdown(); // Initial call to avoid 1-second delay }); }); </script>