SM
← negisameer.live

Blog · 2026-12-04

Migrating 118 static HTML pages to Next.js without moving a pixel

How I ported a static website to Next.js and Tailwind with automated screenshot diffing, and the four CSS details that caused almost all of the drift.

At Famous Drive I moved a chauffeur company's website from 118 hand-maintained HTML files to Next.js, React and Tailwind CSS. The one rule from the client: the new site must look exactly like the old one. Here is how I made "exactly" something a script checks instead of something I hope for.

1. Turn the HTML into data first

The pages shared about 70% of their text; the median page had only about 10 lines of its own. So instead of copying 118 files into 118 components, I wrote an extractor that parses each old page with a real HTML parser and splits it into a typed content model. The result was 94 pages rendered by two templates.

The extractor follows two rules:

  • It never invents content. If something isn't in the source, it isn't on the page.
  • It reports what it couldn't classify into a separate file. A migration that doesn't say what it dropped hasn't been verified.

The generated JSON is committed, so when the content changes, the diff on that one file is the content review.

2. Make "identical" a test

A parity script builds the app, screenshots every old page and its new version at three viewport widths, and fails with a diff image if any pixel moved. A second tool compares the box size and computed styles of matching elements, to answer why something drifted, not just that it did.

The key habit: treat a parity failure as a bug in the change, never as a threshold to raise.

3. The four details that caused the drift

Tailwind's default line-height

Tailwind's preflight sets line-height: 1.5 on the page, and every element inherits it. The old site never set a line height, so its text rendered at the browser's normal (about 1.2). The difference is 1–2px per element, but it adds up: already 3px off by the first heading and growing down the page. Setting line-height: normal on html and body fixed the single biggest source of drift.

@layer base {
  html, body { line-height: normal; }
  p { max-width: 68ch; line-height: 1.7; }
}

Rebuild the cascade, don't flatten it

The old CSS styled the bare p element and let blocks override it. Copying that rule into @layer base kept the small print at the right width (it rendered 294px too wide without it), and because Tailwind utilities beat @layer base, component overrides still win.

Keep the original fonts

next/font is great, but it writes its own @font-face rules and a size-adjusted fallback, which changes text metrics slightly. For a pixel-exact port, the original font files and declarations were copied byte for byte.

A plain img for the hero

next/image adds a wrapper element and its own sizing. The hero needed to stay a simple aspect-ratio: 16/9; object-fit: cover image, so it uses a plain <img>.

4. Don't lose SEO on the way

Old /page.html URLs became clean /page URLs, with a permanent 301 redirect from each old address, so no existing link breaks.

Takeaways

  • Separate content from templates before you migrate anything.
  • Turn the requirement ("looks the same") into an automated test.
  • When a default fights you, write down why you overrode it, or someone will "fix" it back.
Esc
↑↓ to move · Enter to openCtrl K