Building an entire app with a single HTML file
The claim was that a single HTML file could be a real app. HTML is markup, and real apps need a build step, a framework, a server, or so the thinking goes. So I built one to test it. A Pomodoro timer with a task list, in one file, no build step, no framework, no server.
0 focus sessions done
No tasks yet. Add one above, it saves in your browser.
What I built
A focus timer with three modes, 25 minutes for focus, 5 for a short break, 15 for a long one. A task list underneath, add a task, check it off, delete it. The tasks save in localStorage, so they are still there when you come back. And a count of finished focus sessions, because watching the number climb is half the point.
The shape of it
One file, three parts. HTML for the structure, a style block for the CSS, a script block for the JS. No imports, no bundler, nothing to install. You double-click the file and it opens in the browser. No install step at all. Here is the file, start to finish:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pomodoro</title>
<style>
body { font-family: system-ui; max-width: 560px; margin: 40px auto; padding: 0 16px; }
#timer { font-size: 64px; font-family: monospace; text-align: center; }
.tabs, .controls { display: flex; gap: 8px; flex-wrap: wrap; }
.controls { justify-content: center; margin-top: 12px; }
button { padding: 10px 18px; border-radius: 8px; font-size: 14px; font-weight: 600; border: 1px solid #d1d5db; background: #fff; cursor: pointer; }
.tabs button { padding: 8px 14px; font-size: 13px; }
.tabs button.active { background: #2dd4bf; }
#sessions { text-align: center; font-size: 13px; color: #6b7280; margin-top: 8px; }
#done { text-align: center; font-size: 13px; color: #059669; margin-top: 4px; }
.tasks { margin-top: 20px; border-top: 1px solid #e5e7eb; padding-top: 16px; }
.add-row { display: flex; gap: 8px; }
#new-task { flex: 1; padding: 8px 12px; border-radius: 8px; border: 1px solid #d1d5db; font-size: 14px; min-width: 0; }
#task-list { list-style: none; padding: 0; margin-top: 12px; }
#task-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; }
#task-list li span { flex: 1; }
#task-list li.done span { text-decoration: line-through; color: #9ca3af; }
#task-list li button { border: none; background: transparent; cursor: pointer; color: #9ca3af; font-size: 16px; padding: 2px 6px; }
.empty { font-size: 13px; color: #6b7280; margin-top: 12px; }
</style>
</head>
<body>
<h1>Pomodoro</h1>
<div class="tabs">
<button data-mode="focus" class="active">Focus</button>
<button data-mode="shortBreak">Short break</button>
<button data-mode="longBreak">Long break</button>
</div>
<div id="timer">25:00</div>
<div id="done" hidden>Done. Take a break, or start another round.</div>
<div class="controls">
<button id="start">Start</button>
<button id="reset">Reset</button>
</div>
<div id="sessions">0 focus sessions done</div>
<div class="tasks">
<div class="add-row">
<input id="new-task" placeholder="Add a task for this session">
<button id="add">Add</button>
</div>
<p class="empty" id="empty">No tasks yet. Add one above, it saves in your browser.</p>
<ul id="task-list"></ul>
</div>
<script>
const DURATIONS = { focus: 25 * 60, shortBreak: 5 * 60, longBreak: 15 * 60 };
let mode = 'focus';
let secondsLeft = DURATIONS.focus;
let endAt = null;
let timerId = null;
let sessions = 0;
let tasks = JSON.parse(localStorage.getItem('tasks') || '[]');
const timerEl = document.getElementById('timer');
const doneEl = document.getElementById('done');
const startBtn = document.getElementById('start');
const sessionsEl = document.getElementById('sessions');
const listEl = document.getElementById('task-list');
const emptyEl = document.getElementById('empty');
function render(seconds) {
const mm = String(Math.floor(seconds / 60)).padStart(2, '0');
const ss = String(seconds % 60).padStart(2, '0');
timerEl.textContent = mm + ':' + ss;
}
function tick() {
const left = Math.max(0, Math.round((endAt - Date.now()) / 1000));
secondsLeft = left;
render(left);
if (left === 0) {
clearInterval(timerId);
timerId = null;
endAt = null;
startBtn.textContent = 'Start';
doneEl.hidden = false;
if (mode === 'focus') {
sessions += 1;
sessionsEl.textContent = sessions + ' focus session' + (sessions === 1 ? '' : 's') + ' done';
}
}
}
function start() {
const secs = secondsLeft > 0 ? secondsLeft : DURATIONS[mode];
secondsLeft = secs;
render(secs);
endAt = Date.now() + secs * 1000;
timerId = setInterval(tick, 250);
startBtn.textContent = 'Pause';
doneEl.hidden = true;
}
function pause() {
clearInterval(timerId);
timerId = null;
endAt = null;
startBtn.textContent = 'Start';
}
startBtn.addEventListener('click', () => {
if (timerId) { pause(); } else { start(); }
});
document.getElementById('reset').addEventListener('click', () => {
clearInterval(timerId);
timerId = null;
endAt = null;
secondsLeft = DURATIONS[mode];
render(secondsLeft);
startBtn.textContent = 'Start';
doneEl.hidden = true;
});
document.querySelectorAll('.tabs button').forEach((btn) => {
btn.addEventListener('click', () => {
document.querySelectorAll('.tabs button').forEach((b) => b.classList.remove('active'));
btn.classList.add('active');
clearInterval(timerId);
timerId = null;
endAt = null;
mode = btn.dataset.mode;
secondsLeft = DURATIONS[mode];
render(secondsLeft);
startBtn.textContent = 'Start';
doneEl.hidden = true;
});
});
function saveTasks() {
localStorage.setItem('tasks', JSON.stringify(tasks));
}
function renderTasks() {
listEl.innerHTML = '';
emptyEl.hidden = tasks.length !== 0;
tasks.forEach((task) => {
const li = document.createElement('li');
if (task.done) li.classList.add('done');
const box = document.createElement('input');
box.type = 'checkbox';
box.checked = task.done;
box.addEventListener('change', () => {
task.done = !task.done;
saveTasks();
renderTasks();
});
const span = document.createElement('span');
span.textContent = task.text;
const del = document.createElement('button');
del.textContent = '×';
del.setAttribute('aria-label', 'Delete task');
del.addEventListener('click', () => {
tasks = tasks.filter((t) => t.id !== task.id);
saveTasks();
renderTasks();
});
li.append(box, span, del);
listEl.appendChild(li);
});
}
document.getElementById('add').addEventListener('click', () => {
const input = document.getElementById('new-task');
const text = input.value.trim();
if (!text) return;
tasks.push({ id: Date.now(), text, done: false });
saveTasks();
renderTasks();
input.value = '';
});
document.getElementById('new-task').addEventListener('keydown', (e) => {
if (e.key === 'Enter') document.getElementById('add').click();
});
render(secondsLeft);
renderTasks();
</script>
</body>
</html>What worked
More than I expected. The timer counts down, the tasks persist, and it all fits in one file you can send to someone. localStorage just works, and the browser gives you a real app shell for free. I opened the file, started a session, and forgot it was a single HTML file.
Where I hit the wall
The timer, first. My first version used setInterval to subtract a second on every tick, and it drifted when I switched tabs. Browsers throttle timers in background tabs, first to once a second, then to once a minute after five minutes hidden. A tick counter loses exactly the time the browser withholds. The fix is a deadline: store when the session ends and recompute the remaining time from the clock on every tick. That is what the demo above does, and it is the version that stays accurate.
Notifications, second. A Pomodoro wants to tell you when the session ends, even if the tab is closed. That needs a service worker, and a service worker cannot be registered from a file:// URL. The browser blocks it because a service worker needs a secure context, and a file opened from disk is not one. So the single file can count down while it is open, but it cannot tap you on the shoulder after you close it. That is the wall.
And sync. localStorage lives in one browser on one machine. There is no sync without a server, and a single file has no server. The tasks are yours, on this device, and that is as far as they go.