Styling — Dark Theme
Website Rebuild with Next.js
Chapter 5 · Styling — Dark Theme
A deliberately light chapter, like every sibling course's own equivalent — two built-in mechanisms, applied directly to a real project rather than re-derived from scratch: a global stylesheet for the site's own dark theme, and CSS Modules for the breadcrumb's own scoped styling.
The Global Dark Theme
Imported once, in the layout every route already renders inside of automatically — no per-page import needed anywhere, the same structural benefit Chapter 4's own layout finding already established.
CSS Modules for the Breadcrumb
styles.breadcrumb isn't the literal class name "breadcrumb" — Next.js's own build step rewrites it into a unique, hashed class name (something like PageShell_breadcrumb__a1b2c) automatically, so it can never collide with an identically-named class anywhere else in the project, no manual naming convention needed.
Automatic Bundling, Verified Directly
next build and inspecting .next/static/css/ shows exactly that: the compiled global stylesheet and every CSS Module both come out as content-hashed filenames (e.g. a1b2c3d4.css), with zero configuration required to get there. If the file's own content ever changes, the hash changes with it — a genuinely automatic cache-busting guarantee, not something this course had to wire up by hand.
The Full Asset-Bundling Spectrum, Across the Series
| Next.js | Django | Laravel | Rails | Astro | Express | |
|---|---|---|---|---|---|---|
| Approach | Bundles by design | Ships nothing | Pre-wires Vite | Propshaft + Importmap | Scoped styles + plain import | express.static() |
| Cache-busting? | Yes, automatic | No | Yes, via Vite | Yes — content-hash fingerprinting | Build-time hashing | None — manual only |
| Scoping mechanism | CSS Modules — hashed class names | None built in | None built in | None built in | Native scoped <style> blocks | None — plain global CSS |
Hands-On Exercises
Add app/globals.css with the dark theme applied via the root layout's own import, and confirm it applies site-wide across every route.
📄 View solutionAdd a second, unrelated component with its own nav element and its own .breadcrumb class name in a plain (non-Module) CSS file, and confirm PageShell's own CSS-Module-scoped styles never leak into it, and vice versa.
📄 View solutionRun next build, locate the compiled CSS output under .next/static/css/, and confirm the filename is content-hashed. Change a single style rule and rebuild — confirm the hash changes.
📄 View solutionChapter 5 Quick Reference
app/globals.cssimported in the root layout — applies the dark theme site-wide- CSS Modules (
*.module.css) — Next.js's own built-in scoped-styling mechanism; class names are hashed automatically, no collisions possible - Automatic, verified cache-busting —
next buildcontent-hashes every CSS output file with zero configuration - No new material — both mechanisms are Next.js's own built-in defaults, applied directly
- Next chapter: Database with Prisma