<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Countdown Timers</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
color: #333;
}
header {
color: white;
text-align: center;
margin-bottom: 20px;
font-size: 2.5em;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
#add-form {
background: white;
padding: 20px;
border-radius: 15px;
box-shadow: 0 8px 30px rgba(0,0,0,0.2);
display: flex;
gap: 15px;
margin-bottom: 30px;
width: 100%;
max-width: 500px;
}
input {
padding: 12px;
border: 2px solid #ddd;
border-radius: 8px;
flex: 1;
font-size: 16px;
transition: border-color 0.3s;
}
input:focus {
outline: none;
border-color: #667eea;
}
button {
padding: 12px 25px;
background: linear-gradient(135deg, #4CAF50, #45a049);
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
transition: transform 0.2s, box-shadow 0.2s;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
}
.timers {
display: flex;
flex-direction: column;
gap: 20px;
width: 100%;
max-width: 500px;
}
.card {
background: white;
padding: 25px;
border-radius: 15px;
box-shadow: 0 8px 30px rgba(0,0,0,0.15);
display: flex;
justify-content: space-between;
align-items: center;
transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
.name {
font-size: 1.4em;
margin-bottom: 10px;
color: #555;
font-weight: 600;
}
.timer {
font-size: 1.8em;
font-weight: bold;
color: #2c3e50;
font-family: 'Courier New', monospace;
min-height: 1.2em;
}
.expired {
text-decoration: line-through;
color: #e74c3c !important;
font-style: italic;
}
.delete {
background: linear-gradient(135deg, #f44336, #da190b) !important;
padding: 10px 20px;
font-size: 14px;
}
.delete:hover {
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(244, 67, 54, 0.4);
}
.no-timers {
text-align: center;
color: white;
font-size: 1.2em;
padding: 40px;
background: rgba(255,255,255,0.1);
border-radius: 15px;
backdrop-filter: blur(10px);
}
@media (max-width: 600px) {
#add-form {
flex-direction: column;
}
.card {
flex-direction: column;
text-align: center;
gap: 15px;
}
header {
font-size: 2em;
}
}
</style>
</head>
<body>
<header>⏰ Countdown Timers</header>
<form id="add-form">
<input id="name" type="text" placeholder="Event Name (e.g., Birthday, Deadline)" required>
<input id="datetime" type="datetime-local" required>
<button type="button" onclick="addTimer()">Add Timer</button>
</form>
<div id="timers-container" class="timers"></div>
<script>
let timers = JSON.parse(localStorage.getItem('countdownTimers')) || [];
function formatTimeDiff(ms) {
if (ms <= 0) return "Expired!";
const seconds = Math.floor(ms / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
const s = seconds % 60;
const m = minutes % 60;
const h = hours % 24;
return `${days}d ${h.toString().padStart(2, '0')}h ${m.toString().padStart(2, '0')}m ${s.toString().padStart(2, '0')}s`;
}
function saveTimers() {
localStorage.setItem('countdownTimers', JSON.stringify(timers));
}
function updateTimers() {
timers.forEach(t => {
const el = document.getElementById(`timer-${t.id}`);
if (!el) return;
const ms = t.target - Date.now();
if (ms <= 0) {
el.textContent = "Expired!";
el.classList.add('expired');
} else {
el.textContent = formatTimeDiff(ms);
el.classList.remove('expired');
}
});
}
function render() {
const container = document.getElementById('timers-container');
if (timers.length === 0) {
container.innerHTML = '<div class="no-timers">No timers yet. Add one above! 🎉</div>';
return;
}
container.innerHTML = '';
timers.forEach(t => {
const card = document.createElement('div');
card.className = 'card';
card.id = `card-${t.id}`;
card.innerHTML = `
<div>
<h3 class="name">${t.name}</h3>
<div id="timer-${t.id}" class="timer">Loading...</div>
</div>
<button class="delete" onclick="deleteTimer(${t.id})">Delete</button>
`;
container.appendChild(card);
});
updateTimers();
}
function addTimer() {
const nameInput = document.getElementById('name');
const dateInput = document.getElementById('datetime');
const name = nameInput.value.trim();
if (!name) {
alert('Please enter an event name.');
return;
}
const date = new Date(dateInput.value);
if (isNaN(date.getTime())) {
alert('Please enter a valid date and time.');
return;
}
const id = Date.now();
timers.push({ id, name, target: date.getTime() });
saveTimers();
render();
nameInput.value = '';
dateInput.value = '';
}
function deleteTimer(id) {
timers = timers.filter(t => t.id !== id);
saveTimers();
render();
}
// Initialize
render();
setInterval(updateTimers, 1000);
</script>
</body>
</html>
This is a fully self-contained, responsive HTML page for managing multiple countdown timers.
Features:
- Add timers: Enter event name and datetime (supports future dates only recommended, but past dates show "Expired!").
- Real-time updates: Auto-refreshes every second.
- Persistent storage: Timers save to browser's localStorage.
- Delete timers: Per-timer delete button.
- Visual feedback: Expired timers are struck through and red. Hover effects and smooth animations.
- Mobile-friendly: Adapts to small screens.
- No dependencies: Pure HTML/CSS/JS.
Copy-paste into a .html file and open in any browser. Perfect for deadlines, birthdays, launches, etc.! 🚀