← All posts

The Joy of Single-File HTML Apps

Modern front-end development is amazing when you are building a large collaborative product. It is also hilariously over-engineered when you just want to build an interactive dashboard, a retro game walkthrough, or a weekend educational tool.

Over the last year, some of the most fun—and most durable—software I have built has been single-file HTML apps: one .html file containing all the markup, CSS, and vanilla JavaScript needed to run the entire experience.

Why Zero-Build-Step Feels Like a Superpower

When everything lives in index.html:

  • Instant deployment: Double-click it locally, email it to a friend, drop it on any static host, or open it on an offline laptop. No node_modules, no bundler config, no broken lockfile six months later.
  • Longevity: A React app from three years ago often takes an hour of dependency surgery just to boot. A single-file HTML app from ten years ago still opens cleanly in every browser on Earth.
  • AI-friendly iteration: Because the entire app fits comfortably inside a single context window, iterating on layout, state, and visual polish with an LLM is fast and cohesive—no hunting across 14 component files.

What Actually Works Well in a Single File

You would be surprised how far a single HTML file can go with modern browser APIs:

  • Visual dashboards: Inline SVG, HTML5 <canvas>, or a single CDN import (like Chart.js) can render rich, responsive charts with zero backend.
  • Educational games & flashcards: localStorage gives you instant persistence for scores, streaks, and spaced-repetition progress.
  • Interactive guides & calculators: Collapsible checklists, search filters, keyboard shortcuts, and dark mode all take a few dozen lines of clean CSS and vanilla JS.

Patterns That Keep Single-File Code Clean

The main risk of single-file apps is turning into spaghetti once you pass 500 lines. Four simple habits prevent that:

  1. Use CSS Custom Properties (:root variables): Define your palette, spacing, and typography once at the top of <style> so redesigning the whole app takes seconds.
  2. Keep state in one plain JS object: Store your app's state in a single const state = { ... } object, persist it to localStorage on change, and drive updates through a clean render() function.
  3. Separate data from logic: Put your dataset (levels, quiz questions, map nodes, or metrics) in a clean const DATA = [...] block right at the top of <script>.
  4. Use semantic <template> tags or small helper functions: Avoid giant nested document.createElement chains when clean template literals (with proper escaping for any user input) are far easier to read.

When to Graduate to a Full Framework

Single-file HTML isn't a religion. The moment you need user authentication, a multi-user PostgreSQL database, or server-side secrets, graduate to a proper stack (like Flask + React or Next.js).

But for the 80% of personal tools, prototypes, and creative experiments that don't need a server at all, ditching the build step brings back the immediate joy of building for the web.