<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: CodeFromScratch</title>
    <description>The latest articles on DEV Community by CodeFromScratch (@codefromscratch).</description>
    <link>https://dev.to/codefromscratch</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4236990%2F3b6f5af8-8143-4b00-b7ff-40b874440447.png</url>
      <title>DEV Community: CodeFromScratch</title>
      <link>https://dev.to/codefromscratch</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codefromscratch"/>
    <language>en</language>
    <item>
      <title>Tailwind CSS v4: What's New and How to Migrate</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Mon, 30 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/codefromscratch/tailwind-css-v4-whats-new-and-how-to-migrate-ogc</link>
      <guid>https://dev.to/codefromscratch/tailwind-css-v4-whats-new-and-how-to-migrate-ogc</guid>
      <description>&lt;p&gt;Tailwind v4 looks like a version bump and behaves like a different tool. The JavaScript config file you have maintained for years is gone, your design tokens are now real CSS custom properties the browser can read, and the build step got fast enough to stop thinking about. The site you are reading runs v4 in production — here is what changed, what breaks, and how to migrate without losing a week.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuration moves into CSS, and tokens become real
&lt;/h2&gt;

&lt;p&gt;In Tailwind v3, your design system lived in tailwind.config.js — a JavaScript object the build read once and compiled away. The values were real to the build tool and invisible to the browser. If a chart library or a canvas needed your brand colour, you either duplicated the hex code or imported resolveConfig and shipped a chunk of the theme object to the client just to read one string.&lt;/p&gt;

&lt;p&gt;v4 inverts that. Your main CSS file becomes the single source of truth. The three &lt;code&gt;@tailwind&lt;/code&gt; directives are gone, replaced by one import, and the old theme.extend block becomes a &lt;code&gt;@theme&lt;/code&gt; block written in plain CSS.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tailwind.config.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// tailwind.config.js — the v3 way, soon to be deleted&lt;/span&gt;
&lt;span class="kd"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"./src/**/*.{js,ts,jsx,tsx}"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"#3b82f6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;surface&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"#1a1a2e"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;fontFamily&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Cal Sans"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"sans-serif"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"@tailwindcss/typography"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;app/globals.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* app/globals.css — all configuration lives here now */&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s2"&gt;"tailwindcss"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@plugin&lt;/span&gt; &lt;span class="s2"&gt;"@tailwindcss/typography"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;@theme&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;--color-brand&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#3b82f6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;--color-surface&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#1a1a2e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;--font-heading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Cal Sans"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The part that changes how you think: every token in &lt;code&gt;@theme&lt;/code&gt; is emitted as a real custom property on :root. The bg-brand utility compiles to background-color: var(--color-brand). The token exists at runtime, in the browser, and anything can read it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lib/theme.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Read a design token at runtime — in v3 this needed resolveConfig&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;brand&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getComputedStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPropertyValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"--color-brand"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// "#3b82f6" — hand it to a chart, a canvas, a motion value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Charts, canvas drawing, motion values, generated OG images — anything that needs the raw value outside a class name gets it without a second definition. This is not a preference about configuration formats. It is your design tokens moving from build-time constants to a live API.&lt;/p&gt;

&lt;p&gt;The mapping from the old config follows a namespace convention: keys under colors become --color-* variables, fontFamily becomes --font-*, spacing becomes --spacing-*, borderRadius becomes --radius-*. The namespace decides which utilities a token generates — define --color-surface and bg-surface, text-surface, and border-surface all exist.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app/globals.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@theme&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/* colors.brand.primary  -&amp;gt;  --color-brand-primary */&lt;/span&gt;
  &lt;span class="nv"&gt;--color-brand-primary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#3b82f6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="cm"&gt;/* fontFamily.sans  -&amp;gt;  --font-sans */&lt;/span&gt;
  &lt;span class="nv"&gt;--font-sans&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Inter"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="cm"&gt;/* spacing.18  -&amp;gt;  --spacing-18 */&lt;/span&gt;
  &lt;span class="nv"&gt;--spacing-18&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;4.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="cm"&gt;/* borderRadius.xl  -&amp;gt;  --radius-xl */&lt;/span&gt;
  &lt;span class="nv"&gt;--radius-xl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The engine disappears from your workflow
&lt;/h2&gt;

&lt;p&gt;v4 ships a new engine written in Rust. The Tailwind team's published numbers are full builds around five times faster and incremental rebuilds over a hundred times faster, and the second number is the one you feel. Rebuilds on this site stopped being something I wait for — save the file, and the browser already has it.&lt;/p&gt;

&lt;p&gt;The change you will notice every day, though, is not speed. It is the death of the content array. In v3, Tailwind only generated classes it found in the files you listed, and that list was a steady source of quiet failures: add a new folder, forget to extend the glob, and a class works in development but vanishes from &lt;a href="https://codefromscratch.org/blog/ship-nextjs-production?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=tailwind-css-v4-what-s-new-and-how-to-migrate"&gt;the production build&lt;/a&gt;. Write the glob too wide and the build scans node_modules instead.&lt;/p&gt;

&lt;p&gt;v4 detects source files automatically. It walks your project, respects .gitignore, and skips binary files. When the heuristics are not enough — a component library in another workspace package, a folder you want ignored — you steer them with &lt;code&gt;@source&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app/globals.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* v4 scans your project automatically — no content array */&lt;/span&gt;

&lt;span class="cm"&gt;/* Pull in a workspace package it cannot see: */&lt;/span&gt;
&lt;span class="k"&gt;@source&lt;/span&gt; &lt;span class="s2"&gt;"../../packages/ui/src"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/* Exclude a folder the heuristics pick up: */&lt;/span&gt;
&lt;span class="k"&gt;@source&lt;/span&gt; &lt;span class="nt"&gt;not&lt;/span&gt; &lt;span class="s2"&gt;"./legacy"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Autoprefixer and postcss-import leave your dependency list too. Vendor prefixing and import flattening are handled by the engine itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually breaks coming from v3
&lt;/h2&gt;

&lt;p&gt;Most of your markup survives untouched. The breaking changes cluster in three places, and knowing where they are turns a scary upgrade into a boring one.&lt;/p&gt;

&lt;p&gt;First, the renames. The sizing scales for shadows, blur, and border radius all shifted down one notch, and a handful of utilities changed names or disappeared:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;shadow-sm is now shadow-xs, and the bare shadow is now shadow-sm — the same one-notch shift applies to blur and rounded&lt;/li&gt;
&lt;li&gt;outline-none is now outline-hidden; a new outline-none exists that genuinely sets outline-style: none&lt;/li&gt;
&lt;li&gt;ring is now ring-3, because the default ring width dropped from 3px to 1px&lt;/li&gt;
&lt;li&gt;bg-opacity-* and text-opacity-* are gone — use the slash modifier instead, as in bg-black/50&lt;/li&gt;
&lt;li&gt;flex-shrink-0 and flex-grow are now shrink-0 and grow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Second, the changed defaults, which are sneakier because nothing fails. Border and divide utilities now default to currentColor instead of gray-200, and rings default to currentColor instead of blue-500. A page can compile cleanly and look subtly wrong — borders suddenly dark, focus rings the wrong colour. You find these with your eyes, not with the compiler.&lt;/p&gt;

&lt;p&gt;Third, the toolchain. The PostCSS plugin moved into its own package, &lt;code&gt;@tailwindcss/postcss&lt;/code&gt;, and Vite projects should switch to the dedicated &lt;code&gt;@tailwindcss/vite&lt;/code&gt; plugin for the fastest path. This site runs the PostCSS route under Next.js, and the whole config is six lines:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;postcss.config.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// postcss.config.mjs — the entire file in v4&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"@tailwindcss/postcss"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Plugins changed shape as well. JavaScript plugins load through a &lt;code&gt;@plugin&lt;/code&gt; directive in your CSS rather than a plugins array. First-party plugins like typography work that way today, and some are simply obsolete — container queries are built into core now. Community plugins that reach into v3 internals are the real risk; check each one for v4 support before you start.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; After the upgrade, a leftover tailwind.config.js is silently ignored. It sits in your repo looking authoritative, you edit it, and nothing happens — no warning, no error. Delete it once migration is done, or load it explicitly with &lt;code&gt;@config&lt;/code&gt; "./tailwind.config.js" while you transition.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Run the upgrade tool first, then make the manual passes
&lt;/h2&gt;

&lt;p&gt;The official tool does the mechanical work and does it well: it updates dependencies, swaps the &lt;code&gt;@tailwind&lt;/code&gt; directives for the import, converts your config into a &lt;code&gt;@theme&lt;/code&gt; block, renames utilities across your templates, and rewrites the PostCSS setup. It needs Node 20 or newer, and it edits files in place, so give it a branch of its own.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# new branch, Node 20+, then let the tool do the mechanical work&lt;/span&gt;
git checkout -b update/tailwind-v4
npx @tailwindcss/upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then come the manual passes, which is the part people skip and regret:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read the entire diff before committing anything — the tool is good, but it just edited your templates&lt;/li&gt;
&lt;li&gt;Search for class names the tool cannot see: strings built with concatenation, classes stored in a CMS or a database, anything assembled at runtime&lt;/li&gt;
&lt;li&gt;Do a visual sweep of every page for the changed defaults — borders, rings, shadows, placeholder text&lt;/li&gt;
&lt;li&gt;Delete the leftovers: tailwind.config.js, autoprefixer, postcss-import&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On a mid-sized app, expect the tool to take a minute and the manual passes to take an afternoon. That is the honest budget.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dark mode is where CSS variables earn their keep
&lt;/h2&gt;

&lt;p&gt;v4's dark: variant follows prefers-color-scheme by default. The moment you add a theme switcher you need class-based theming instead, and you redefine the variant once with &lt;code&gt;@custom-variant&lt;/code&gt;. But the better pattern barely uses dark: at all. Define semantic tokens — background, foreground, muted — that flip per theme, and expose them to Tailwind with &lt;code&gt;@theme&lt;/code&gt; inline:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app/globals.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s2"&gt;"tailwindcss"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/* class-based theming instead of prefers-color-scheme */&lt;/span&gt;
&lt;span class="k"&gt;@custom-variant&lt;/span&gt; &lt;span class="nt"&gt;dark&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;.dark&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.dark&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;--background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;oklch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.99&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;--foreground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;oklch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.21&lt;/span&gt; &lt;span class="mf"&gt;0.02&lt;/span&gt; &lt;span class="mi"&gt;260&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.dark&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;--background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;oklch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.17&lt;/span&gt; &lt;span class="mf"&gt;0.02&lt;/span&gt; &lt;span class="mi"&gt;260&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;--foreground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;oklch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.96&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/* expose the semantic names as utilities */&lt;/span&gt;
&lt;span class="k"&gt;@theme&lt;/span&gt; &lt;span class="nt"&gt;inline&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;--color-background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--background&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;--color-foreground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--foreground&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now bg-background and text-foreground exist as utilities, and they flip with the theme automatically because they resolve to a variable the .dark class redefines. The inline keyword matters: it tells Tailwind to reference the variable directly in the generated utility instead of baking in its current value, so the lookup happens at runtime, per theme. Your markup stays clean — dark: survives for genuine one-offs, not for every surface and text colour on the page. This site pairs the pattern with next-themes, which sets the class on the html element and nothing more.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;@utility&lt;/code&gt; replaces the old escape hatches
&lt;/h2&gt;

&lt;p&gt;Custom utilities used to go in &lt;code&gt;@layer&lt;/code&gt; utilities and mostly worked — until you put hover: or md: in front of one and discovered that variants did not apply. The &lt;code&gt;@utility&lt;/code&gt; directive registers your CSS as a first-class utility, variants included.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app/globals.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@utility&lt;/span&gt; &lt;span class="nt"&gt;scrollbar-hidden&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;scrollbar-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;-webkit-scrollbar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;hover:scrollbar-hidden and md:scrollbar-hidden now behave like any built-in class. That single change removes most of the reasons projects accumulated a components.css nobody wanted to own.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Audit your arbitrary values while you are in there. Most bracket habits from v3 — w-[4.5rem], mt-[52px], grid-cols-[repeat(16,minmax(0,1fr))] — were workarounds for a frozen scale. v4 derives spacing from a single --spacing token, so w-18 and mt-13 just work, and grid-cols-16 generates on demand. After migration, brackets should be rare enough to raise an eyebrow in code review.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What changed after 4.0: versions 4.1, 4.2 and 4.3
&lt;/h2&gt;

&lt;p&gt;v4 kept moving after the big release. Each of these is a minor version inside v4, so the configuration in this guide still applies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;4.1 (April 2025):&lt;/strong&gt; text-shadow-* and mask-* utilities, &lt;code&gt;@source not&lt;/code&gt; and &lt;code&gt;@source inline()&lt;/code&gt; for controlling what gets scanned, user-valid / user-invalid and pointer-fine / pointer-coarse variants, and better support for older Safari and Firefox.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;4.2 (February 2026):&lt;/strong&gt; an official webpack plugin (&lt;code&gt;@tailwindcss/webpack&lt;/code&gt;), four new colour palettes (mauve, olive, mist, taupe), logical-property utilities such as &lt;code&gt;pbs-*&lt;/code&gt;, &lt;code&gt;mbs-*&lt;/code&gt;, &lt;code&gt;inline-*&lt;/code&gt;, &lt;code&gt;block-*&lt;/code&gt; and &lt;code&gt;inset-s-*&lt;/code&gt;, and &lt;code&gt;font-features-*&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;4.3 (May 2026):&lt;/strong&gt; scrollbar utilities (&lt;code&gt;scrollbar-thin&lt;/code&gt;, &lt;code&gt;scrollbar-thumb-*&lt;/code&gt;), &lt;code&gt;zoom-*&lt;/code&gt;, &lt;code&gt;tab-*&lt;/code&gt;, &lt;code&gt;@container-size&lt;/code&gt;, and &lt;code&gt;@variant&lt;/code&gt; with stacked and compound variants.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the time of writing the newest release is 4.3.5 (November 2026). For anything after that, the &lt;a href="https://github.com/tailwindlabs/tailwindcss/releases" rel="noopener noreferrer"&gt;official release notes&lt;/a&gt; are the source.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to wait, and the checklist when you go
&lt;/h2&gt;

&lt;p&gt;v4 is the right default for new projects and for most existing ones. There are three situations where waiting is the smarter call.&lt;/p&gt;

&lt;p&gt;If your build leans on several community plugins, check every one before touching anything. The plugin API changed, and a plugin that patches v3 internals will not survive the jump. One unported plugin you can replace by hand; three that you genuinely depend on means the migration timeline is not yours to control yet.&lt;/p&gt;

&lt;p&gt;If your design system is mid-flight — tokens being renamed, palette under discussion — finish that first. Migrating the config format while the values inside it are churning produces diffs nobody can review and regressions nobody can bisect. One migration at a time.&lt;/p&gt;

&lt;p&gt;And check your browser floor. v4 targets Safari 16.4, Chrome 111, and Firefox 128 as minimums, because it builds on cascade layers and modern colour functions. If your audience includes older browsers — some enterprise and government contexts still do — v3 keeps working. It will not get new features, but it does not rot either.&lt;/p&gt;

&lt;p&gt;When you are ready, this is the whole migration in order:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a branch and confirm you are on Node 20 or newer&lt;/li&gt;
&lt;li&gt;Run npx &lt;code&gt;@tailwindcss/upgrade&lt;/code&gt; and read every line of the diff&lt;/li&gt;
&lt;li&gt;Switch the toolchain: &lt;code&gt;@tailwindcss/postcss&lt;/code&gt; for PostCSS setups, &lt;code&gt;@tailwindcss/vite&lt;/code&gt; for Vite&lt;/li&gt;
&lt;li&gt;Hunt down dynamic class names the tool cannot rewrite — concatenated strings, CMS content&lt;/li&gt;
&lt;li&gt;Verify each plugin has v4 support and load it with &lt;code&gt;@plugin&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Move remaining theme values into &lt;code&gt;@theme&lt;/code&gt;, then delete tailwind.config.js or wire it temporarily with &lt;code&gt;@config&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Visually re-check borders, rings, shadows, and placeholders — the defaults moved&lt;/li&gt;
&lt;li&gt;Convert &lt;code&gt;@layer&lt;/code&gt; utilities blocks to &lt;code&gt;@utility&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Set up semantic dark-mode tokens with &lt;code&gt;@theme&lt;/code&gt; inline&lt;/li&gt;
&lt;li&gt;Remove autoprefixer and postcss-import from package.json, then run a full production build&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the production app feels too risky for a first attempt, do not start there. Take a side project or a half-finished portfolio site and migrate that this week — the whole exercise fits in an evening on a small codebase, and you will hit every category of problem once, at low stakes. By the time you point the upgrade tool at something that matters, the diff will read like a checklist you have already worked through. No side project at hand? A &lt;a href="https://codefromscratch.org/blog/pricing-table-from-scratch-css?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=tailwind-css-v4-what-s-new-and-how-to-migrate"&gt;pricing table from scratch&lt;/a&gt; is about the right size, and &lt;a href="https://codefromscratch.org/blog/css-flexbox-vs-grid-real-layouts?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=tailwind-css-v4-what-s-new-and-how-to-migrate"&gt;Flexbox vs Grid on real layouts&lt;/a&gt; covers the layout calls you'll make in it.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/tailwind-css-v4-what-s-new-and-how-to-migrate?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=tailwind-css-v4-what-s-new-and-how-to-migrate"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=tailwind-css-v4-what-s-new-and-how-to-migrate"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tailwindcss</category>
    </item>
    <item>
      <title>Prisma vs Drizzle: How to Choose Your TypeScript ORM</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Fri, 27 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/codefromscratch/prisma-vs-drizzle-how-to-choose-your-typescript-orm-2nlb</link>
      <guid>https://dev.to/codefromscratch/prisma-vs-drizzle-how-to-choose-your-typescript-orm-2nlb</guid>
      <description>&lt;p&gt;Search for prisma vs drizzle and you will find a dozen comparisons that end the same way: both are great, it depends. True, and useless. This is the comparison I wanted when I picked the data layer for this site — the same schema and the same query written both ways, the trade-offs that actually decide it, and a hard rule at the end.&lt;/p&gt;

&lt;p&gt;Prisma and Drizzle are not two implementations of the same idea. They are two answers to a question most teams never ask out loud: should your application code see SQL, or should SQL be an implementation detail? Everything else — the schema syntax, the query API, the migration story, the bundle weight — follows from that answer. The ORM is also one of the stickiest choices in the whole stack; I mapped where it sits among the rest in &lt;a href="https://codefromscratch.org/blog/modern-full-stack-2026?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=prisma-vs-drizzle-decision"&gt;the modern full-stack guide&lt;/a&gt;, but this is the one decision you will live with in every feature you ship.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two philosophies, not two products
&lt;/h2&gt;

&lt;p&gt;Prisma is schema-first. You describe your data model in its own small language, in a schema.prisma file, and everything else is generated from it: the typed client, the migration SQL, the TypeScript types. When you query, you describe the shape of data you want and Prisma writes the SQL. You can go months without reading a SELECT statement, and for a lot of teams that is exactly the point.&lt;/p&gt;

&lt;p&gt;Drizzle is SQL-first. The schema is TypeScript — exported constants describing tables and columns. Queries are method chains that mirror SQL almost one to one: select, from, innerJoin, where, orderBy. There is no generation step for the client and no engine sitting between you and the database driver. Drizzle's pitch is unusually honest: if you know SQL, you already know Drizzle.&lt;/p&gt;

&lt;p&gt;This framing matters more than any feature table, because features converge — both projects ship fast and copy each other's good ideas — but philosophies do not. Prisma will never make SQL the primary interface. Drizzle will never hide it. Whichever you pick becomes the dialect your team reads and writes every working day, for years.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same schema, written two ways
&lt;/h2&gt;

&lt;p&gt;Abstract philosophy is cheap, so here is the same two-table model — users and their posts — written in both. Prisma first:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;prisma/schema.prisma&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
  id    String @id @default(uuid())
  email String @unique
  name  String
  posts Post[]
}

model Post {
  id        String   @id @default(uuid())
  title     String
  published Boolean  @default(false)
  createdAt DateTime @default(now())
  author    User     @relation(fields: [authorId], references: [id])
  authorId  String
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anyone can read this, including people who have never touched Prisma. The relation is declared on both sides, so the generated client can walk it in either direction: user.posts and post.author both exist. The cost is that this is a separate language. Your editor needs a plugin for it, you cannot compose it with code, and generating twenty similar tables programmatically is off the table. The schema is data, not code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;db/schema.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;pgTable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timestamp&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"drizzle-orm/pg-core"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;pgTable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"users"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;primaryKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defaultRandom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;pgTable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"posts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;primaryKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defaultRandom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;published&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"created_at"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defaultNow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"author_id"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;references&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is plain TypeScript. You can share a timestamps helper across every table, derive column sets programmatically, and refactor the schema with the same tools you use on the rest of the codebase. Notice also what is missing: there is no posts field on users. If you want nested reads through Drizzle's relational query API, relations are declared separately, in a second file Prisma users never write. And the definition reads like a transcript of CREATE TABLE — precise, but noisier than the Prisma version of the same model.&lt;/p&gt;

&lt;h2&gt;
  
  
  The join test: queries are where you live
&lt;/h2&gt;

&lt;p&gt;Schemas are written once and queries are written daily, so this section should carry the most weight in your decision. The task: the twenty most recent published posts, each with its author's name and email.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lib/queries.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;recent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;published&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;orderBy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"desc"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;take&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;include&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// recent[0].author.name — typed, nested, no join in sight&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Prisma you think in object graphs. The result shape mirrors the query shape — nested author objects, fully typed — and the SQL that produced it is invisible. That is the feature and the risk in one sentence: Prisma decides whether this becomes one join or two queries, and an include nested three levels deep can hide a query plan you would never have approved by hand.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lib/queries.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;desc&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"drizzle-orm"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;recent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;authorName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;authorEmail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;innerJoin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;published&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;orderBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Drizzle you think in SQL. The join is on the page, the result is flat rows shaped exactly as you selected them, and the cost of the query is legible because you wrote it. Fairness requires a footnote here: Drizzle also ships a relational query API — db.query.posts.findMany with a with clause — that reads almost like Prisma's include. It works well, but it is the second way of doing things in a library whose identity is the first way, and most Drizzle codebases I have read stay with the builder.&lt;/p&gt;

&lt;p&gt;On type inference, both are excellent, and the differences are mechanical rather than qualitative. Prisma generates its types ahead of time, so they are always exactly right — but you must rerun prisma generate after every schema change, and until you do, your editor lies to you. Drizzle infers types from the schema file at compile time, so there is nothing to regenerate — but on large schemas the type-level machinery can visibly slow the TypeScript language server. Neither problem should decide the choice. Both will mildly annoy you.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Whichever you pick, turn on query logging in development from day one — log: ['query'] in the Prisma client options, logger: true in Drizzle's. Reading the SQL your ORM actually emits is how you catch the accidental N+1 before your users feel it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Migrations: managed for you, or generated for you
&lt;/h2&gt;

&lt;p&gt;Prisma owns the whole migration lifecycle. You edit the schema, run one command, and Prisma diffs it against the database, writes the SQL, applies it, and records it in a history table. It also detects drift — someone hot-fixing a column type straight in production — and refuses to continue until you reconcile.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx prisma migrate dev --name add-published-flag
&lt;span class="c"&gt;# diffs schema.prisma, writes prisma/migrations/&amp;lt;timestamp&amp;gt;_.../, applies it&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Drizzle splits the same job into two honest halves. drizzle-kit generate diffs your TypeScript schema and emits plain SQL files; drizzle-kit migrate applies them. The expectation, stated and real, is that you read the SQL before it runs. For local prototyping, drizzle-kit push skips the files entirely and syncs the schema straight to the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx drizzle-kit generate   &lt;span class="c"&gt;# writes plain SQL to ./drizzle/&lt;/span&gt;
npx drizzle-kit migrate    &lt;span class="c"&gt;# applies pending migrations&lt;/span&gt;
npx drizzle-kit push       &lt;span class="c"&gt;# prototype mode: sync schema, no files&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trade-off shows at the edges. Prisma's workflow is smoother right up to the moment you need something it cannot express — a data backfill between two schema steps, a concurrent index on a large table — and then you are hand-editing generated SQL inside a workflow that did not expect you. Drizzle assumed from day one that you would read and sometimes write the SQL, so its awkward cases are less awkward.&lt;/p&gt;

&lt;p&gt;Raw SQL escape hatches follow the same pattern. Prisma's $queryRaw is a parameterised tagged template that lives outside the typed world unless you adopt TypedSQL on top of it. Drizzle's sql fragments compose directly into the query builder, so you can drop one raw expression — a window function, a full-text rank — into an otherwise typed query. If you expect to reach for raw SQL weekly rather than yearly, that composability is worth more than any benchmark in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Serverless weight is a smaller story than it used to be
&lt;/h2&gt;

&lt;p&gt;For years the strongest argument against Prisma was physical: it shipped its query engine as a separate binary, and on serverless platforms that meant fat deployments and slow cold starts. That argument has mostly expired. Recent major versions replaced the binary engine with a client written in TypeScript, and the cold-start gap to Drizzle shrank from a headline to a footnote. Drizzle is still the lighter library — plain TypeScript, no generation step, comfortable inside edge runtimes with strict size limits — and if those limits are your reality, it remains the safer default. But if you ruled Prisma out in 2023 for weight, the 2026 facts deserve a re-check.&lt;/p&gt;

&lt;p&gt;What decides serverless performance more than either ORM is what sits between your function and your database: connection pooling, HTTP drivers, and the platform hosting Postgres itself. A function that opens a fresh connection on every invocation will be slow with either library; one that goes through a pooler will be fine with both. I compared the platforms and their pooling stories in &lt;a href="https://codefromscratch.org/blog/managed-postgres-comparison?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=prisma-vs-drizzle-decision"&gt;the managed Postgres comparison&lt;/a&gt; — get that layer right before you blame the ORM for your latency.&lt;/p&gt;

&lt;h2&gt;
  
  
  The honest driver: how much SQL do you want to see
&lt;/h2&gt;

&lt;p&gt;Strip away the benchmarks and the feature tables and the choice usually reduces to one question: how much SQL does your team actually know, and how much of it do you want visible in the codebase? If you think in SQL — if you sketch the query before you write the application code, if EXPLAIN output is information rather than noise — Drizzle reads like comfort. Prisma in that situation feels like talking to your own database through an interpreter.&lt;/p&gt;

&lt;p&gt;If you learned data modelling through application code — and most self-taught developers did — Prisma's abstraction is not a limitation, it is the feature. The schema is legible at a glance, queries match how you already think about your data, and the things SQL makes you get right by hand are simply handled. Drizzle in that situation is homework: doable, probably even good for you, but homework. Neither answer is a deficiency. The mistake is choosing the tool for the team you wish you had instead of the team you have.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; The expensive failure mode is not picking the wrong ORM — both are good enough that you would ship either way. It is switching mid-project. An ORM touches every query, every migration, and half your tests; swapping one costs weeks of careful work and delivers exactly nothing your users will notice. Pick once, with eyes open, and stay.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This site runs Prisma 7 in production. I chose it because I work alone, I want a schema I can read at a glance after six months away from a model, and I would rather review one generated migration than hand-verify SQL at midnight before a deploy. That whole journey, including the parts that bit — like learning to read the SQL hiding behind a nested include — is documented in &lt;a href="https://codefromscratch.org/blog/prisma-orm-from-zero-to-production?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=prisma-vs-drizzle-decision"&gt;Prisma from zero to production&lt;/a&gt;. I have not regretted the choice. I also will not pretend Drizzle would have failed me; it would not have.&lt;/p&gt;




&lt;h2&gt;
  
  
  The decision rule
&lt;/h2&gt;

&lt;p&gt;Here is the rule, with no hedge.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose Prisma if your team thinks in objects more than in SQL, you want a schema a junior can read on day one, and you want migrations managed end to end with drift detection.&lt;/li&gt;
&lt;li&gt;Choose Prisma if you are a solo developer or a small product team where every hour not spent on the data layer goes into the product — that arithmetic is the entire point of the abstraction.&lt;/li&gt;
&lt;li&gt;Choose Drizzle if your team already thinks in SQL and would be writing these joins by hand anyway — the near one-to-one mapping converts existing knowledge into immediate productivity.&lt;/li&gt;
&lt;li&gt;Choose Drizzle if you deploy to edge runtimes with hard size limits, or your queries regularly outgrow what a query abstraction expresses cleanly and the composable raw-SQL escape hatch would see weekly use.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Still torn? Two tiebreakers. Default to Prisma if the phrase connection pooler meant nothing to you before this article — the managed workflow protects you from a class of mistakes you have not met yet. Default to Drizzle if an ORM has ever made you angry by hiding a query from you, because that anger does not fade with time. It compounds.&lt;/p&gt;

&lt;p&gt;Then make it concrete. Take the real schema of the thing you are building — not the users-and-posts toy from this article — write it in both, and write your three hairiest queries in both. That is one afternoon, it converts my conclusions into your own, and it is the last time this question should cost you anything. After that, commit, go deep on the one you chose, and let the other go. Projects do not stall because someone picked the wrong ORM. They stall because someone kept comparing.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/prisma-vs-drizzle-decision?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=prisma-vs-drizzle-decision"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=prisma-vs-drizzle-decision"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>postgres</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Why Courses Leave You Feeling Like You Know Nothing</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Wed, 25 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/codefromscratch/why-courses-leave-you-feeling-like-you-know-nothing-4a8e</link>
      <guid>https://dev.to/codefromscratch/why-courses-leave-you-feeling-like-you-know-nothing-4a8e</guid>
      <description>&lt;p&gt;You finished the course. You did every exercise. And you still feel exactly like you did on day one. I know that feeling well, and today I want to explain why it happens, why it is not your fault, and what to do instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let me guess how your last course ended
&lt;/h2&gt;

&lt;p&gt;You found a course. Maybe it was free, maybe you paid for it. You watched every video, you typed along, you did the exercises. Find the prime numbers in a loop. Pull a name out of an array. Reverse a string.&lt;/p&gt;

&lt;p&gt;Then the last video ended, the certificate popped up, and you opened an empty folder to build something of your own. And nothing came. You stared at the screen and felt like you knew nothing at all.&lt;/p&gt;

&lt;p&gt;I have been exactly there. When I started, I had one problem that never went away: where do I even learn this, and in what order? There is so much material online and almost nobody is direct with you. They teach you things you will never use, and nothing connects to anything else. You finish a course and you feel the same as before you started.&lt;/p&gt;

&lt;p&gt;So first, the most important thing I want you to hear. It was not you. You are not too slow, and you are not missing some talent that other people have.&lt;/p&gt;

&lt;h2&gt;
  
  
  The real reason: nobody shows you where the exercise lives
&lt;/h2&gt;

&lt;p&gt;Think about what a typical exercise teaches you. How to loop over a list. How to read one item out of an array. These are real skills, and you do need them. But they are taught as little islands. Nobody takes you by the hand and says: this exact thing is what draws the product list on a web shop.&lt;/p&gt;

&lt;p&gt;A real website is not a pile of separate tricks. It is a handful of simple ideas, connected, repeated hundreds of times. The loop you practiced is the same loop that puts ten blog posts on a page. The array of names is the same kind of data that holds your users, your products, your comments.&lt;/p&gt;

&lt;p&gt;When a course teaches the idea without the connection, you do the exercise, you pass the quiz, and you walk away without the one thing you actually needed: the picture of how the pieces fit together. That is why you feel like you know nothing. You know the pieces. Nobody gave you the map.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The exercises are toy problems, so you never see where the skill is used.&lt;/li&gt;
&lt;li&gt;Each lesson stands alone, so nothing builds into one whole.&lt;/li&gt;
&lt;li&gt;Watching feels like progress, but only building makes it stick.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Let me show you where one of those exercises lives
&lt;/h2&gt;

&lt;p&gt;Here is the classic exercise. You have a list of names and you print them one by one.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;names.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Emily"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"James"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Olivia"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read it slowly. The first line creates a list with three names. The word for is the loop. It says: take the list, and for each item in it, run the code between the curly braces. Each time around, name holds the next item. First Emily, then James, then Olivia. Run it and you get three lines in the console. That is the whole exercise.&lt;/p&gt;

&lt;p&gt;Now look at what a web shop does. It has a list of products, and it needs one card on the page for each product. Same shape, different data. Instead of printing a name, we build a little piece of HTML.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;products.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Wireless Mouse"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"mouse.jpg"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Mechanical Keyboard"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"keyboard.jpg"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"USB-C Hub"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;39.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"hub.jpg"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;renderCard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`&amp;lt;article class="card"&amp;gt;
  &amp;lt;img src="${product.image}" alt="${product.name}"&amp;gt;
  &amp;lt;h2&amp;gt;${product.name}&amp;lt;/h2&amp;gt;
  &amp;lt;p&amp;gt;$${product.price.toFixed(2)}&amp;lt;/p&amp;gt;
&amp;lt;/article&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;renderCard&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me walk through every part, because this is the moment the exercise turns into real work.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;products is still a list, but each item is now an object with a name, a price and an image. This is what real data looks like. Your database returns something very close to this.&lt;/li&gt;
&lt;li&gt;renderCard takes one product and returns a string of HTML for one card. Notice it knows nothing about the list. One job: turn one product into one card.&lt;/li&gt;
&lt;li&gt;The backticks let us drop values into the text with the dollar sign and curly braces. product.name becomes Wireless Mouse. The extra dollar sign in front of the price is just a real dollar sign.&lt;/li&gt;
&lt;li&gt;toFixed(2) makes sure 89 prints as 89.00. Prices with one decimal look broken to a customer, so we always force two.&lt;/li&gt;
&lt;li&gt;products.map(renderCard) is the loop in a shorter form. It runs renderCard on every product and gives back a new list of cards. join puts them together into one block of HTML.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run it and you get three finished cards, each one built from the same function, only the content is different. If tomorrow you have three hundred products, you do not write three hundred cards. You change nothing. That is the whole point of a loop, and now you have seen it do something real.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Notice what we did not do. We did not copy and paste the card three times. When you catch yourself pasting the same block again and again with only the text changed, that is the signal to write one function and loop over the data. Good programmers are lazy in exactly this way.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is the aha I want you to have. The prime numbers, the arrays, the loops: they are not school problems. They are the engine under every list you have ever scrolled on a website.&lt;/p&gt;

&lt;p&gt;If you are still building your first page and want the structure behind those cards, start with &lt;a href="https://codefromscratch.org/blog/html-css-beginners-build-first-web-page?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=why-courses-leave-you-feeling-like-you-know-nothing"&gt;the beginner guide to HTML and CSS&lt;/a&gt;, and if you want to see how cards sit in a layout, &lt;a href="https://codefromscratch.org/blog/css-grid-layout-the-complete-visual-guide?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=why-courses-leave-you-feeling-like-you-know-nothing"&gt;the complete CSS Grid guide&lt;/a&gt; shows you how.&lt;/p&gt;

&lt;h2&gt;
  
  
  Same idea, three levels deep
&lt;/h2&gt;

&lt;p&gt;I like to write for everyone, so here is how that same example looks depending on where you are.&lt;/p&gt;

&lt;h3&gt;
  
  
  If you are just starting
&lt;/h3&gt;

&lt;p&gt;A loop repeats something. A function packs one job into a name you can reuse. If you understood only that, you understood the most important part. Do not worry about the rest yet. Type the example, change the names and prices, and watch the output change. That is learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  If you have built a few things
&lt;/h3&gt;

&lt;p&gt;The better habit is separating the data from the way it looks. Data in one place, one small function that turns a single item into a card, and a loop that connects them. When a client says make the price red, you change one line, not three hundred. If your last project had the same markup pasted in many places, this is the fix.&lt;/p&gt;

&lt;h3&gt;
  
  
  If you have been around for a while
&lt;/h3&gt;

&lt;p&gt;Here is the part courses almost never mention, and it is the part that gets people in trouble. We put product.name straight into HTML. For our own hardcoded list that is fine. The moment that text comes from a user, a form, a comment, or any outside source, it is dangerous.&lt;/p&gt;

&lt;p&gt;Imagine someone types a name that is actually a piece of HTML with a script inside. If you drop it straight into the page, the browser runs it. That is called cross-site scripting, and it is one of the oldest ways to attack a site. The fix is to escape the text first, so the browser shows it as plain text instead of running it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;escape-html.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;escapeHtml&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&amp;amp;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&amp;amp;amp;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&amp;amp;lt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&amp;amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'"'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&amp;amp;quot;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&amp;amp;#39;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;evil&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;img src=x onerror="alert(1)"&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;escapeHtml&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;evil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run this and the output is &amp;lt;img src=x onerror="alert(1)"&amp;gt;. The dangerous characters turned into harmless text. The browser prints the weird name on the page instead of executing it. Each replaceAll swaps one special character for its safe version. The ampersand goes first, because otherwise we would escape the ampersands we just created.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Modern tools like React escape text for you automatically, which is one more reason to use them. But if you ever build HTML by hand from strings, escape anything that came from outside. Think three steps ahead: where does this text come from, and who could have written it?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How I would learn it if I started again
&lt;/h2&gt;

&lt;p&gt;I believe you learn on a real project, starting easy and getting harder. Not exercises in isolation. Pick something real and small. A web shop page that lists products. An app that keeps track of your own inventory. A cash register for a small shop. You learn the loop because the shop needs a list. You learn functions because you are tired of copying the card. You learn escaping because you realize someone could type anything.&lt;/p&gt;

&lt;p&gt;Every concept arrives the moment you need it, attached to a reason. That is why it sticks, and why the pieces finally connect into one picture instead of staying as separate facts.&lt;/p&gt;

&lt;p&gt;One more thing I did the hard way. I used to start projects with no plan and no sketch. I built from my head until it looked good to me, and I never thought about semantic HTML, about search engines, about security, about what happens when real users show up. It works right up until it does not. Now I start with a plan, a rough visual, and a few questions: who uses this, what can go wrong, what is my Plan B? If you want the longer version of that thinking, read &lt;a href="https://codefromscratch.org/blog/production-grade-code-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=why-courses-leave-you-feeling-like-you-know-nothing"&gt;what separates hobby apps from real ones&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The advice about studying two or three hours every day
&lt;/h2&gt;

&lt;p&gt;You have probably heard that you must study two or three hours every day, no exceptions. I disagree, especially when you are starting. People are not machines. Some days your head is somewhere else, you are sick, you are tired, and code simply does not go in. Forcing it on those days teaches you one thing: to hate it.&lt;/p&gt;

&lt;p&gt;So take a day or two off when you need it. But be careful with the other side of that. Do not let the break turn into a week, then a month. Without a rhythm you do not build a habit, and you forget what you learned. The goal is a routine you can keep for years, not a streak you break in two weeks.&lt;/p&gt;

&lt;p&gt;And here is a number I like. Getting one percent better in a day feels like nothing. But stack 365 of those days and you are in a completely different place than someone who did nothing. Small steps are not a weakness. They are how everyone who is good got there.&lt;/p&gt;

&lt;h2&gt;
  
  
  You will feel stuck, and that is normal
&lt;/h2&gt;

&lt;p&gt;I wanted to program since I was about twelve. My older cousin went to a technical school, and I looked up to him. I saw what he did, I liked it immediately, and I never changed my mind. Later I had to start my education all over again in a new country, because of the language. It was not a straight line. There were detours, there were days I felt behind, and there were many things I did not know.&lt;/p&gt;

&lt;p&gt;What I learned is that not knowing yet is fine. Plenty of people who work at big companies do not know everything, and they ask other people for help all the time. Nobody has the whole map in their head. The people who get good are the ones who keep going when they cannot see the way out.&lt;/p&gt;

&lt;p&gt;Find something you love enough that it does not feel like a chore. For me it is programming. Some mornings I get up early to work on it, and some evenings and weekends I sit down to build something nobody is paying me for, because I want to. That is not advice to overwork. It is the opposite: when you love it, it does not feel like work, and you find the energy without forcing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do right now
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Pick one tiny real thing to build this week: a page with a list of items, for example. Not a tutorial project, something you actually care about. If you use AI while you build it, here is &lt;a href="https://codefromscratch.org/blog/learn-web-development-from-scratch-with-ai?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=why-courses-leave-you-feeling-like-you-know-nothing"&gt;what to learn yourself and what to let AI do&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Type the product card example above, then change it. Add a field, break it on purpose, fix it.&lt;/li&gt;
&lt;li&gt;Write down one question you cannot answer yet. Questions are your map.&lt;/li&gt;
&lt;li&gt;Come back here. Every article on this blog starts from a real problem and ends with the piece that finally clicks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A last thing, and I mean it. You can do this, and you have to believe that. If I thought you were not capable of it, I would not spend my time on you. Just do not give up, and you will always have me on your side.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/why-courses-leave-you-feeling-like-you-know-nothing?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=why-courses-leave-you-feeling-like-you-know-nothing"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=why-courses-leave-you-feeling-like-you-know-nothing"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React State Management in 2026: Zustand vs Redux vs Context</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Mon, 23 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/codefromscratch/react-state-management-in-2026-zustand-vs-redux-vs-context-2h7h</link>
      <guid>https://dev.to/codefromscratch/react-state-management-in-2026-zustand-vs-redux-vs-context-2h7h</guid>
      <description>&lt;p&gt;Liquid syntax error: Unknown tag 'endraw'&lt;/p&gt;
</description>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>One Card, Many Posts: Render Lists Without Repeating Code</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Fri, 20 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/codefromscratch/one-card-many-posts-render-lists-without-repeating-code-4p2p</link>
      <guid>https://dev.to/codefromscratch/one-card-many-posts-render-lists-without-repeating-code-4p2p</guid>
      <description>&lt;p&gt;You've got a page with twelve blog cards on it, and every card is the same block of HTML copied and pasted with a different title. Now someone asks you to add the author's name to every card. Today I'll show you how to write a card once and let the data fill it in, in plain JavaScript first and then in React and Next.js, so a change like that is one edit instead of twelve.&lt;/p&gt;

&lt;p&gt;Here's the short answer, so you have it before anything else. Put the things that change, like the title, the text, the image and the date, in a list of data. Write the markup for one card once, as a function or a component. Then loop over the list and call that function for every item. Change the function and every card changes with it. That's the whole pattern behind every blog list, product grid and feed you've ever scrolled.&lt;/p&gt;

&lt;p&gt;If you're a beginner, read this top to bottom, and click the live demo in the middle, because seeing it is worth more than my words. If you already loop over arrays every day, jump to the section about innerHTML, and then the one about keys in React. Those two are where people who know the basics still get hurt. The last sections, on missing data, dates, big lists and code an AI wrote for you, are for those of you who review other people's code.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: twelve copies of the same card
&lt;/h2&gt;

&lt;p&gt;This is how almost everyone starts. You build one card, it looks good, so you copy it. Then you copy it again. Here are three of them, and in a real page there would be twelve.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"grid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/images/css.webp"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"A stylesheet open next to a web page"&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"320"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"180"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;First steps with CSS&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Colors, spacing and fonts, explained from zero.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;time&lt;/span&gt; &lt;span class="na"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"2026-10-12"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Oct 12, 2026&lt;span class="nt"&gt;&amp;lt;/time&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/images/forms.webp"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"A sign-up form with two fields"&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"320"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"180"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;How forms work&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;What really happens when you press submit.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;time&lt;/span&gt; &lt;span class="na"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"2026-10-19"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Oct 19, 2026&lt;span class="nt"&gt;&amp;lt;/time&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/images/errors.webp"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"A red error message in the browser console"&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"320"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"180"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Reading error messages&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;The red text is trying to help you.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;time&lt;/span&gt; &lt;span class="na"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"2026-10-26"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Oct 26, 2026&lt;span class="nt"&gt;&amp;lt;/time&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look at what's actually different between those blocks. The image file, the alt text, the title, one sentence and a date. Everything else, the article tag, the class names, the order of the elements, the width and height of the image, is identical. You typed the same structure three times to change five small values.&lt;/p&gt;

&lt;p&gt;And it works. That's the trap. Nothing is broken on the day you write it. It breaks on the day something changes. Someone asks for the author's name under the title, and now you open the file and make the same edit twelve times. You'll miss one. You'll put the name above the title in card seven because you were tired. Or a new post comes out and you copy the block again, and the new card quietly has last month's date because you forgot to change it.&lt;/p&gt;

&lt;p&gt;Here's the thing that annoys me about how this gets taught. Courses love exercises like pulling a name out of an array, and you do it, and you have no idea where that shows up in a real website. This is where it shows up. A list of blog posts is an array. A card is what you do with one item of it. I wrote more about that gap in &lt;a href="https://codefromscratch.org/blog/why-courses-leave-you-feeling-like-you-know-nothing?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=render-lists-without-repeating-code"&gt;why courses leave you feeling like you know nothing&lt;/a&gt;, and this article is one of the places where the pieces finally connect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why HTML makes you repeat yourself
&lt;/h2&gt;

&lt;p&gt;HTML isn't a programming language. It's a description of a document: here's a heading, here's a paragraph, here's an image. It has no way to say "do this for every post". There's no loop in HTML, no variables, no functions. If you've only written HTML so far, like in &lt;a href="https://codefromscratch.org/blog/html-css-beginners-build-first-web-page?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=render-lists-without-repeating-code"&gt;building your first web page&lt;/a&gt;, copying is the only tool you have. So you're not doing anything wrong. You've just reached the edge of what HTML can do by itself.&lt;/p&gt;

&lt;p&gt;To go past that edge you need something that can repeat things for you. In the browser that's JavaScript. On a server it could be any language: PHP, Python, JavaScript again in Node.js. The idea is the same everywhere, which is why it's worth learning properly once.&lt;/p&gt;

&lt;p&gt;Think about wedding invitations. Nobody designs two hundred invitations. Somebody designs one card, with a blank where the guest's name goes. Then there's a guest list. And then for every name on the list, somebody prints the card and writes that name in the blank. One design, one list, one repeated action. If the date of the wedding changes, you fix the design once, and every invitation printed after that is right.&lt;/p&gt;

&lt;p&gt;Your blog cards are exactly that. The card design is the template. The guest list is your data. Printing one card per guest is the loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea: separate the data from the template
&lt;/h2&gt;

&lt;p&gt;So we split the page into three parts, and each part has one job.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The data: a list of posts, where each post is a small bundle of values. Title, excerpt, date, image, alt text. This is the only part that changes when you publish something new.&lt;/li&gt;
&lt;li&gt;The template: the markup of one card, written once, with blanks where the values go.&lt;/li&gt;
&lt;li&gt;The loop: a few lines that walk through the data and fill in the template for each item.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's start with the data. In JavaScript, a list is an array and a bundle of named values is an object. So a list of posts is an array of objects.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;posts.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"first-steps-with-css"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"First steps with CSS"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;excerpt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Colors, spacing and fonts, explained from zero."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-10-12"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/images/css.webp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;imageAlt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"A stylesheet open next to a web page"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"how-forms-work"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"How forms work"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;excerpt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"What really happens when you press submit."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-10-19"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/images/forms.webp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;imageAlt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"A sign-up form with two fields"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go through it. The square brackets make an array, which is just a list with an order. Inside it, each pair of curly braces is one object, which is one post. Inside the object, every line is a name and a value: slug is "first-steps-with-css", title is "First steps with CSS", and so on. The comma between the two objects separates the posts.&lt;/p&gt;

&lt;p&gt;Why is there a slug? It's the post's unique name, the part that ends up in the address bar. We don't show it on the card right now, but we'll need something that's different for every post later, when React asks for keys. Give every item in a list a unique ID from the start and you'll thank yourself.&lt;/p&gt;

&lt;p&gt;Why is the date written as "2026-10-12" and not as "Oct 12, 2026"? Because the data should store the fact, and the template should decide how to show it. That year-month-day format is unambiguous and it sorts correctly as plain text. How it looks to a reader is a display decision, and we'll make it in one place.&lt;/p&gt;

&lt;p&gt;And notice that imageAlt is its own field. Alt text describes the image for people who can't see it. It belongs to each post, because every image is different. If you skip it here, there's nowhere sensible to add it later.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Terms in plain words. An array is an ordered list of values. An object is a bundle of named values, like a form someone filled in. A function is a named piece of code you can run again and again with different inputs. A loop is code that repeats something once for every item in a list. The DOM is the browser's live version of your HTML, the thing JavaScript can change after the page has loaded.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 1: write the card once, as a function
&lt;/h2&gt;

&lt;p&gt;Now the template. We write a function that takes one post and gives back one finished card. Every value from the post goes into the right place, and the structure is written exactly once.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;render-dom.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;dateFormat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"en-US"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;dateStyle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"medium"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"UTC"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createCard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"article"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;className&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"card"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;img&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"img"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;alt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imageAlt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;320&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"h2"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;excerpt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"p"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;excerpt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;excerpt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"time"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dateTime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dateFormat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;excerpt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Line by line, because every line is there for a reason.&lt;/p&gt;

&lt;p&gt;The first line creates a date formatter. Intl.DateTimeFormat is built into every modern browser and into Node.js, and it turns a date into text for a given language. "en-US" with dateStyle "medium" gives you "Oct 12, 2026". We create it once, outside the function, because there's no reason to build a new formatter for every single card. The timeZone part looks odd, and I'll explain it properly in the section about dates, because it fixes a real bug.&lt;/p&gt;

&lt;p&gt;Then function createCard(post). This is our template. It takes one post, the one object, and the word post is just the name we give it inside the function.&lt;/p&gt;

&lt;p&gt;document.createElement("article") makes a new article element. It isn't on the page yet. It only exists in memory, like a card on your desk that hasn't been put in the envelope. Then we give it the class name "card" so the CSS can style it.&lt;/p&gt;

&lt;p&gt;Next comes the image. We set src from post.image and alt from post.imageAlt, so each card gets its own picture and its own description. The width and height are the same for every card, which is why they're written here and not in the data. They tell the browser how much space to reserve before the image downloads, so the page doesn't jump around while it loads.&lt;/p&gt;

&lt;p&gt;The title, the excerpt and the time all follow the same move: create the element, then put text into it with textContent. Remember that word. textContent means "treat this as text, never as HTML". It matters a lot, and you'll see exactly why in a minute.&lt;/p&gt;

&lt;p&gt;The time element gets two things. dateTime holds the machine-readable date, the "2026-10-12" from the data, so browsers, search engines and screen readers know what it means. textContent holds the human version, "Oct 12, 2026". Same fact, two audiences.&lt;/p&gt;

&lt;p&gt;Finally, card.append adds all four children to the article, in that order, and return card hands the finished card back to whoever called the function. That's the whole template. If you want the author's name under the title tomorrow, you add two lines here and every card on the page gets it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: loop over the data and put the cards on the page
&lt;/h2&gt;

&lt;p&gt;We have data and we have a template. The loop is the shortest part.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mount.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#posts"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fragment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createDocumentFragment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;fragment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;createCard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceChildren&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fragment&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line finds the container on the page, the element with the id "posts". That's an empty div you put in your HTML where the cards should appear.&lt;/p&gt;

&lt;p&gt;Then we create a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment" rel="noopener noreferrer"&gt;DocumentFragment&lt;/a&gt;. Think of it as a tray. Instead of carrying each card to the page one at a time, you put them all on the tray and carry the tray over once. The page gets updated in one go.&lt;/p&gt;

&lt;p&gt;for (const post of posts) is the loop. Read it out loud: for each post of the posts. On every round, post is the next object from the array, and we pass it to createCard and drop the result on the tray.&lt;/p&gt;

&lt;p&gt;The last line, list.replaceChildren(fragment), clears whatever was inside the container and puts the cards there. Using replace instead of append means you can run this again later, after sorting or filtering, without ending up with the old cards and the new cards both on the page.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Honest note on the tray. For ten or twenty cards you will not see any difference between appending each card directly and using a fragment. I use it because it's the same amount of code and it's the habit that holds up when the list gets long. If you appended one by one and it works, you didn't write a bug.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's three files and maybe forty lines of JavaScript, and it doesn't matter anymore whether you have three posts or three hundred. The page you write stays the same size. Only the data grows.&lt;/p&gt;

&lt;h2&gt;
  
  
  See it run: one function, any number of cards
&lt;/h2&gt;

&lt;p&gt;Here it is live. Every card below comes from one createCard function and a small array. Click Add a post and watch a new card appear, with no new HTML written. Click Oldest first to sort the same data the other way. Empty the list to see what happens when there's nothing to show. Leave the checkbox alone for now. It's for the next section.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; Card list from data. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/render-lists-without-repeating-code?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=render-lists-without-repeating-code"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The colored blocks stand in for images, because the demo can't load pictures. In a real page that's the img element from Step 1.&lt;/p&gt;

&lt;p&gt;Notice what sorting did. We didn't move any HTML around. We sorted the data and drew the cards again. That's a habit worth building early: change the data, then render again. Don't reach into the page and shuffle elements by hand. When the data is the truth and the page is just a picture of the data, a whole class of bugs disappears, because the picture can never drift away from the truth.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shortcut everyone writes, and why it bites: innerHTML
&lt;/h2&gt;

&lt;p&gt;If you search for how to render a list, or ask an AI to do it, there's a good chance you'll get something like this instead of createElement. It's shorter and it looks like HTML, which feels nicer.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;render-string.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;cardHTML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`
    &amp;lt;article class="card"&amp;gt;
      &amp;lt;img src="${post.image}" alt="${post.imageAlt}" width="320" height="180"&amp;gt;
      &amp;lt;h2&amp;gt;${post.title}&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;${post.excerpt}&amp;lt;/p&amp;gt;
      &amp;lt;time datetime="${post.date}"&amp;gt;${post.date}&amp;lt;/time&amp;gt;
    &amp;lt;/article&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#posts"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cardHTML&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what it does. cardHTML takes a post and returns one long string of HTML, with the values dropped in using a template literal, the text between backticks where ${...} inserts a value. Then &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noopener noreferrer"&gt;posts.map(cardHTML)&lt;/a&gt; runs that function on every post and gives you a new array of strings, one per card. join("") glues them into one big string, and innerHTML hands that string to the browser to turn into elements.&lt;/p&gt;

&lt;p&gt;It works, and for text you wrote yourself it's fine. The problem is the word innerHTML. It means "read this string as HTML". So if any value contains something that looks like a tag, the browser builds that tag.&lt;/p&gt;

&lt;p&gt;Now check the live demo above and tick "Use innerHTML for titles". The third card's title is literally Why &amp;lt;em&amp;gt;keys&amp;lt;/em&amp;gt; matter, with the tags as part of the text. With textContent, you see the tags as characters, which is correct: that's the title. With innerHTML, the word keys turns italic, because the browser treated the text as markup.&lt;/p&gt;

&lt;p&gt;Italic text is harmless. But what if the title came from a user, or a form, or a database somebody else can write to? I ran the innerHTML version with a title containing an img tag with an onerror attribute, and the browser created a real img element inside the h2. In a real browser, that onerror code runs. That's called cross-site scripting, XSS for short: somebody else's code running on your page, with access to everything your page can see.&lt;/p&gt;

&lt;p&gt;I ran the same title through the createCard version, the one using textContent, and the h2 had zero child elements. The tag was just text on the screen. MDN says it directly on the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML" rel="noopener noreferrer"&gt;innerHTML page&lt;/a&gt;: when the content is plain text, use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent" rel="noopener noreferrer"&gt;textContent&lt;/a&gt; instead.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; The rule I follow: data goes in with textContent, setAttribute or element properties like img.src. innerHTML only gets strings I wrote myself, never anything that came from a user, a form, a URL or a database. If you must turn outside data into HTML, it needs a sanitizer, and that's a decision for someone who understands the trade-off, not a quick fix.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There's a middle way you'll meet in older code and some libraries: the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/template" rel="noopener noreferrer"&gt;template element&lt;/a&gt;. You write the card's HTML once inside a template tag on the page, the browser doesn't show it, and JavaScript clones it for each post and fills the blanks with textContent. It gives you real HTML to look at and the safe way of filling it in. It's a good tool. I'm not showing the full version here because it's the same idea as createCard with different plumbing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dates, missing fields and the empty list
&lt;/h2&gt;

&lt;p&gt;This is the part tutorials skip, and it's where real data hurts you. Demo data is perfect. Real data isn't.&lt;/p&gt;

&lt;h3&gt;
  
  
  The date that shows up one day early
&lt;/h3&gt;

&lt;p&gt;Remember the timeZone: "UTC" in our formatter? Here's why it's there. A date written as "2026-10-12", with no time, is read by JavaScript as midnight UTC. That's documented on &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date" rel="noopener noreferrer"&gt;MDN's Date page&lt;/a&gt;: date-only forms are interpreted as UTC, date-time forms as local time. When a formatter then shows that moment in the reader's own time zone, anyone west of UTC sees the evening before.&lt;/p&gt;

&lt;p&gt;I checked it. The same "2026-10-12" formatted for Los Angeles prints "Oct 11, 2026". Your post says it was published on a different day depending on where the reader lives. Telling the formatter to use UTC as well means it reads and shows the date in the same zone, so everyone sees Oct 12. If your dates carry a real time, like a comment posted at 14:05, then you probably do want the reader's local time, and you'd drop that option. It depends on what the date means.&lt;/p&gt;

&lt;h3&gt;
  
  
  One broken item takes down the whole list
&lt;/h3&gt;

&lt;p&gt;Now, what if one post has no date? Maybe someone saved a draft without one. I ran createCard on a post with the date missing, and it threw: RangeError: Invalid time value. And because the loop runs all the cards in one go, that one error stops everything. Not one broken card. No cards at all.&lt;/p&gt;

&lt;p&gt;So the formatting gets a guard.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;format-date.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;formatDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNaN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;dateFormat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;new Date(value) tries to read the value as a date. If it can't, you get an invalid date, and getTime on an invalid date returns NaN, which means "not a number". Number.isNaN checks exactly that. If the date is invalid we return null, and the card can simply leave the date out. If it's fine, we format it as before. I ran it with "2026-10-19", with nothing, and with the text "next week", and got "Oct 19, 2026", null and null.&lt;/p&gt;

&lt;p&gt;The better fix is one step earlier: check the shape of the data when it enters your app, so a post without a date never reaches the template. That's what &lt;a href="https://codefromscratch.org/blog/zod-at-trust-boundaries?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=render-lists-without-repeating-code"&gt;validating at trust boundaries with Zod&lt;/a&gt; is about. The guard in the template is your Plan B for when the check upstream misses something.&lt;/p&gt;

&lt;h3&gt;
  
  
  Zero posts is a state too
&lt;/h3&gt;

&lt;p&gt;Empty the list in the demo. If you don't plan for it, an empty array gives you an empty div and a page that looks broken. One if at the top of your render function fixes it: when there are no items, show a sentence instead. It costs three lines and it's the difference between "the site is down" and "there's nothing here yet".&lt;/p&gt;

&lt;h2&gt;
  
  
  The same idea in React: components and map
&lt;/h2&gt;

&lt;p&gt;If you're working in React or Next.js, nothing about the idea changes. The function that makes one card is now called a component, and the loop is &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noopener noreferrer"&gt;map&lt;/a&gt;. Here's the card.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;components/PostCard.tsx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@/lib/posts"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;dateFormat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"en-US"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;dateStyle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"medium"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"UTC"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;PostCard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt; &lt;span class="n"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"card"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imageAlt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;320&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;excerpt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="n"&gt;dateTime&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;dateFormat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line imports the Post type, which is a TypeScript description of what one post looks like: slug, title, excerpt, date, image and imageAlt, all strings. It means your editor will complain if you forget a field or misspell one, before the browser ever sees it.&lt;/p&gt;

&lt;p&gt;The formatter is created once, outside the component, for the same reason as before. Then PostCard is a function that receives props, and we pull post out of them. What it returns looks like HTML but it's JSX: className instead of class, curly braces where a value goes, and dateTime with a capital T.&lt;/p&gt;

&lt;p&gt;Here's something important for the innerHTML story. When you put {post.title} in JSX, React treats it as text, the same as textContent. I rendered this component with that nasty img title and React wrote it out as escaped text, not as a tag. React has a way to insert raw HTML, and it's deliberately named dangerouslySetInnerHTML so you notice when you use it. If you see it in a code review next to user data, stop and ask questions.&lt;/p&gt;

&lt;p&gt;Now the list.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;components/PostList.tsx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@/lib/posts"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;PostCard&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./PostCard"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;PostList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;No&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="n"&gt;yet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nc"&gt;The&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;its&lt;/span&gt; &lt;span class="n"&gt;way&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"grid"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PostCard&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The if at the top is our empty state from earlier. Then posts.map runs once per post and returns one PostCard per post. map gives back a new array, here an array of cards, and React knows how to render an array of elements. That's the loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why React asks for a key
&lt;/h3&gt;

&lt;p&gt;Look at key={post.slug}. If you leave it out, the page still renders, but React prints a warning in the console. I ran it to be sure: "Each child in a list should have a unique key prop."&lt;/p&gt;

&lt;p&gt;Here's why it exists. When your list changes, React doesn't throw the page away and draw it fresh. It compares the new list with the old one and changes only what's different. To do that it has to know which card is which. Picture a dinner table where the waiter remembers orders by seat number. If two guests swap seats, the coffee goes to the wrong person. If he remembers orders by name, the coffee follows the person. The key is the name.&lt;/p&gt;

&lt;p&gt;That's also why the array index, the 0, 1, 2 position, is a bad key when the list can be sorted, filtered or added to at the top. After a sort, item number 0 is a different post, so React thinks the post at seat 0 just changed its title. The &lt;a href="https://react.dev/learn/rendering-lists" rel="noopener noreferrer"&gt;React docs on rendering lists&lt;/a&gt; say that index as a key often leads to subtle and confusing bugs, and they also warn against generating keys on the fly with something like Math.random. Every render would create new keys, so React would throw away and rebuild every card each time. Use something stable that belongs to the item: a database ID or a slug.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the data comes from in Next.js
&lt;/h2&gt;

&lt;p&gt;In a real site the posts don't sit in a hand-written array. They come from a database or a content system. In Next.js with the App Router, the page itself can be an async server component that fetches the posts and hands them to the list. If server components are new to you, &lt;a href="https://codefromscratch.org/blog/react-server-components-explained?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=render-lists-without-repeating-code"&gt;React Server Components explained&lt;/a&gt; covers what runs where.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app/blog/page.tsx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Metadata&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"next"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;PostList&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@/components/PostList"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;getPosts&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@/lib/posts"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Metadata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Blog"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;BlogPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getPosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Blog&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PostList&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;getPosts is your own function that reads from wherever your posts live. The page waits for it with await, then passes the result to PostList. That's it. The page doesn't know or care whether there are two posts or two thousand.&lt;/p&gt;

&lt;p&gt;There's a second reason I like this setup. Because the component runs on the server, the finished cards are already in the HTML the browser receives. With the plain JavaScript version, the cards only exist after the script runs. Google can run JavaScript, and its &lt;a href="https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics" rel="noopener noreferrer"&gt;JavaScript SEO basics&lt;/a&gt; explain how, but HTML that already contains the content is the simpler path. I used to think SEO didn't matter much. It does: the best content is invisible if Google never shows it.&lt;/p&gt;

&lt;h2&gt;
  
  
  So that's all it is
&lt;/h2&gt;

&lt;p&gt;Take away the syntax and every version in this article is the same three things. A list of data. One template that knows how to draw one item. A loop that connects them. createElement and a for loop, map and a component, a server page and a database: same idea, different clothes.&lt;/p&gt;

&lt;p&gt;Once you see it, you'll see it everywhere. The product grid in a shop. The rows in your email inbox. The comments under a video. Search results. Every one of them is somebody's data, one template and a loop. When you look at a page now, you can ask: what's the data here, and what's the template? That question is a big step from copying blocks of HTML.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to watch out for, and your Plan B
&lt;/h2&gt;

&lt;p&gt;This is the section for when it's not a demo anymore.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Very long lists. Hundreds of cards are fine. Thousands of rich cards on one page get slow to build and slow to scroll. The usual answer is pagination, showing twenty at a time, which is also friendlier to readers. For truly huge lists, like a table with tens of thousands of rows, there's a technique called virtualization that only draws the rows on screen. Don't reach for it until you measure a problem.&lt;/li&gt;
&lt;li&gt;Images in a grid. Always set width and height, as in Step 1, so the layout doesn't jump. Cards below the first screen can use loading="lazy" so the browser fetches them only when they're close to view. The first visible image should load normally.&lt;/li&gt;
&lt;li&gt;Alt text comes from the data. Repeating the title as alt text is not a description. If the image is decorative, an empty alt is honest. If your data has no alt field, that's a gap in your data, not in your template.&lt;/li&gt;
&lt;li&gt;Duplicate keys. If two posts accidentally share a slug, React warns about duplicate keys and the list can behave strangely. Unique keys are a data rule, so enforce them where the data is created, for example with a unique constraint in the database.&lt;/li&gt;
&lt;li&gt;Headings inside cards. If the page has an h1 and the cards sit directly below it, h2 in the card is right. If the list sits inside a section that already has an h2, the cards should use h3. One template means the heading level is decided in one place, so make it a prop when the card is used in different places.&lt;/li&gt;
&lt;li&gt;Code an AI wrote for you. When you ask an AI for a card grid, it will often reach for a template string and innerHTML, because that's short. Check for it. I use AI for a lot of my work and I check what it writes as far as I can, and this is exactly the kind of thing worth checking, because it works perfectly on demo data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the Plan B for the whole approach: if something goes wrong inside a list in React, one broken card can still take down the page. Guard the risky parts, like the date, and for bigger apps put an error boundary around sections that render outside data. &lt;a href="https://codefromscratch.org/blog/error-boundaries-done-right?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=render-lists-without-repeating-code"&gt;Error boundaries done right&lt;/a&gt; shows how. If your plan B is "hope the data is always clean", that's not a plan B.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to learn next
&lt;/h2&gt;

&lt;p&gt;Your cards need a layout, and a wall of equal cards is a grid job. &lt;a href="https://codefromscratch.org/blog/css-flexbox-vs-grid-real-layouts?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=render-lists-without-repeating-code"&gt;Flexbox vs Grid on real layouts&lt;/a&gt; explains the repeat and minmax grid the demo above is built on, and why it wraps into new rows by itself. After that, try writing a test for PostList that checks the empty state and the number of cards; &lt;a href="https://codefromscratch.org/blog/testing-react-applications-a-complete-strategy?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=render-lists-without-repeating-code"&gt;testing React applications&lt;/a&gt; shows how to set that up.&lt;/p&gt;

&lt;p&gt;Then try it on your own page. Find anything you copied more than twice, pull the values that change into an array, and write the template once. The first time it feels like more work than copying. The second time you need to change something, it pays for itself.&lt;/p&gt;

&lt;p&gt;I learned most of this by doing it the long way first and getting it wrong. That's fine. Not knowing something yet is fine. You can do this, and you have to. If you weren't capable I wouldn't spend my time on you. Just don't give up, and you'll always have me on your side.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/render-lists-without-repeating-code?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=render-lists-without-repeating-code"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=render-lists-without-repeating-code"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>html</category>
      <category>react</category>
    </item>
    <item>
      <title>NextAuth vs Better Auth vs Rolling Your Own: Picking Auth in 2026</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Wed, 18 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/codefromscratch/nextauth-vs-better-auth-vs-rolling-your-own-picking-auth-in-2026-1d0b</link>
      <guid>https://dev.to/codefromscratch/nextauth-vs-better-auth-vs-rolling-your-own-picking-auth-in-2026-1d0b</guid>
      <description>&lt;p&gt;Search for NextAuth alternatives in 2026 and half the results still recommend Lucia — a library its own author shut down. Auth advice rots faster than any other corner of the ecosystem, so here is the comparison rebuilt from scratch: NextAuth, Better Auth, hosted services, and writing your own sessions, judged on the one question that outlives every version bump — who owns your user table.&lt;/p&gt;

&lt;h2&gt;
  
  
  Auth is a data decision wearing a library costume
&lt;/h2&gt;

&lt;p&gt;Most dependencies are replaceable. You can swap a date library in an afternoon and a state manager in a weekend, because the blast radius is your own code. Auth is different, because its state does not live in your code. It lives in password hashes in a database, in session cookies sitting in browsers you do not control, and in OAuth account links that pair your user IDs with Google's. Whatever you choose, you are really choosing where that data lives and what it costs to move.&lt;/p&gt;

&lt;p&gt;That gives you the only taxonomy worth using. On one side sit the systems where the user table lives in your own database: NextAuth with a database adapter, Better Auth, and hand-rolled sessions. On the other, systems where it lives in someone else's cloud: Clerk and Auth0. Supabase Auth straddles the line — a hosted service writing into your own Postgres. Every other comparison point, provider lists and plugin counts and developer experience, matters less than this one, because this is the one you cannot refactor your way out of.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://codefromscratch.org/blog/modern-full-stack-2026?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=nextauth-vs-lucia-vs-better-auth"&gt;the modern full-stack overview&lt;/a&gt; I called auth one of the load-bearing picks in a 2026 stack. This article is the long version of that chapter, written from the slightly bruised position of actually running one of these libraries in production.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Write the user-export script in week one, while it is trivial: a query that dumps users, password hashes, and OAuth account links to a file. It costs ten minutes today and is your migration insurance forever. If a system — library or hosted — cannot produce that file, you have just learned the most important thing about it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Lucia is a cautionary tale, not a candidate
&lt;/h2&gt;

&lt;p&gt;From roughly 2023 to 2024, Lucia was the thinking developer's answer to NextAuth: a small, readable session library from a single maintainer, with documentation good enough that people read it for fun. Then the author deprecated it. Not because of a security failure or a rug-pull — the conclusion was more interesting than that. Maintaining the package meant absorbing endless adapter requests and framework edge cases, while the actual core of the problem, database-backed sessions, was a couple of hundred lines that most developers could own themselves. So he sunset the library and rebuilt the project as a learning resource that teaches you to write that code.&lt;/p&gt;

&lt;p&gt;Take both lessons from that. The first is about dependency risk: an auth library maintained by one person is one burnout away from becoming your problem, and auth is the worst place to inherit a problem, because you cannot simply stop patching it. Before adopting any auth dependency, check the bus factor as seriously as you would check its security history. The second lesson is the author's own: sessions are small. That insight outlived the library that carried it, and it is why rolling your own gets a serious section below instead of a warning sticker.&lt;/p&gt;

&lt;p&gt;What Lucia is not, in 2026, is a candidate. If an article recommends installing it, the article is dated — which makes it a usefully reliable freshness test for everything else that article claims.&lt;/p&gt;

&lt;h2&gt;
  
  
  NextAuth v5: the longest provider list and the longest beta
&lt;/h2&gt;

&lt;p&gt;NextAuth is the incumbent. It rebranded to Auth.js as it grew beyond Next.js, though its centre of gravity never really moved — and its provider list remains the longest in the ecosystem by a wide margin. Not just Google and GitHub but the long tail: Keycloak, Okta, Azure AD, the identity provider your enterprise client insists on. If the requirement is "log in with anything", NextAuth probably has the config for it already.&lt;/p&gt;

&lt;p&gt;The v5 story tells you the rest. The redesign was genuinely good — one auth() call that behaves identically in server components, route handlers, server actions, and middleware, replacing the three different session APIs of v4:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app/dashboard/page.tsx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;auth&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@/lib/auth"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;redirect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"next/navigation"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;DashboardPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/login"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Welcome&lt;/span&gt; &lt;span class="n"&gt;back&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The release process was not good. The beta stretched across years, documentation for v4 and v5 coexisted and contradicted each other, and tutorials written six months apart described what looked like different libraries. The internals are opaque in a way you only discover at debugging time: when a callback fires in an order you did not expect, or a session cookie outgrows the size limit and gets silently chunked, the error messages give you almost nothing, and you end up reading the library's source to understand your own login flow.&lt;/p&gt;

&lt;p&gt;This site runs the v5 beta in production with Google, GitHub, and credentials sign-in, so I will be precise about the deal. The OAuth plumbing — handshakes, CSRF, cookie handling — is excellent and has years of production scrutiny behind it. Everything above that line is yours. NextAuth ships no multi-factor auth, treats email-and-password as a deliberately second-class citizen, and offers callbacks where you might expect features: our TOTP MFA — enrollment, QR codes, recovery codes, the verification step wedged into the credentials flow — is entirely hand-built. The complete setup, including the parts the library leaves to you, is in &lt;a href="https://codefromscratch.org/blog/authentication-in-next-js-with-nextauth-js-v5?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=nextauth-vs-lucia-vs-better-auth"&gt;the NextAuth v5 guide&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; If you run the v5 beta in production, pin the exact version in package.json — no caret — and read the changelog before every bump. The beta has been stable in practice for a long time, but "beta" still means the maintainers reserve the right to move things.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Better Auth ships the features NextAuth makes you build
&lt;/h2&gt;

&lt;p&gt;Better Auth is the rising option, and it grew fast because its pitch lands exactly where NextAuth users are sore: most applications need the same ten auth features, so the library should ship them instead of pointing you at a blog post. It is TypeScript-first, framework-agnostic, and built around a plugin architecture. The core covers email-and-password, social providers, and database-backed sessions; plugins add two-factor auth, passkeys, and organizations with roles and invitations. Rate limiting on auth endpoints is built in rather than left as an exercise.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lib/auth.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;betterAuth&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"better-auth"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;prismaAdapter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"better-auth/adapters/prisma"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;twoFactor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;organization&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"better-auth/plugins"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;prisma&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@/lib/prisma"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;betterAuth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;prismaAdapter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"postgresql"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;emailAndPassword&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;socialProviders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;github&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;GITHUB_CLIENT_ID&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;clientSecret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;GITHUB_CLIENT_SECRET&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;twoFactor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;organization&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those two plugin calls are the headline. On top of NextAuth, two-factor auth alone is a multi-week project — I know because we built it — and organizations are a schema design exercise you do unsupervised. Just as important is where the data lands: Better Auth's CLI generates its tables into your own database, through Prisma, Drizzle, or plain SQL. Your users, hashes, sessions, and org structures sit in your Postgres, in readable tables, so the exit cost stays bounded even if the project vanished tomorrow.&lt;/p&gt;

&lt;p&gt;The honest trade-offs are all variations of young. NextAuth's core has been hammered in production for years; Better Auth's much larger surface — every plugin is auth-critical code — has had a fraction of that time under load. Plugin schemas evolve, which means database migrations you did not plan. And after Lucia, sustainability deserves an explicit line in your evaluation: the project is active and widely adopted, but "the direction is good" was said about every project that later stalled. The schema ownership is exactly what makes that bet acceptable — the failure mode is a fork or a slow migration, not a hostage situation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clerk and Auth0 trade money for time — and keep the user table
&lt;/h2&gt;

&lt;p&gt;Every library comparison hides a question in plain sight: why install one at all? Clerk gives you sign-in components, MFA, organizations, and a dashboard a non-technical cofounder can operate, in an afternoon. Auth0 has been selling the enterprise version of the same promise for over a decade. For a two-person startup whose biggest risk is irrelevance rather than lock-in, taking that deal is often simply correct, and pretending otherwise is wishful thinking from people who enjoy building auth.&lt;/p&gt;

&lt;p&gt;The costs are just as real, and they compound. Pricing is per monthly active user, which means your auth bill grows precisely when your product succeeds — a generous free tier becomes a serious line item without you changing a single line of code, and you discover the jump at the worst possible moment, mid-growth. And your users live in someone else's database. Export paths exist, but an export is a project: data to sync out, password hashes to request — some providers hand them over, on some plans — and live sessions that will not survive the move. You will run that project under pressure, because nobody migrates auth while things are going well.&lt;/p&gt;

&lt;p&gt;Supabase Auth occupies the middle of this trade: a hosted service you do not maintain, with users stored in your own Postgres next to the rest of your data. If your stack already leans on Supabase it is the natural default, and &lt;a href="https://codefromscratch.org/blog/supabase-authentication-complete-guide-with-next-js?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=nextauth-vs-lucia-vs-better-auth"&gt;the Supabase authentication guide&lt;/a&gt; covers that path end to end, including row-level security — the part that actually requires thinking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rolling your own is back on the table — if you get four things right
&lt;/h2&gt;

&lt;p&gt;This is what the Lucia author now recommends learning, and after years of treating hand-rolled auth as a punchline, the honest position has shifted: rolling your own OAuth is still a bad idea, but rolling your own sessions is a bounded, learnable problem. The core fits in one file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lib/session.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;createHash&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:crypto"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;prisma&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@/lib/prisma"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nf"&gt;createHash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"sha256"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"hex"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;validateSession&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findUnique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;include&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expiresAt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A sessions table, a long random token generated at login, hashed before it is stored so a database leak does not leak live sessions, an expiry check, a delete on the way out. Add a create function and sliding expiration and the whole layer is under two hundred lines you can read in one sitting and own forever. The migration story is the best on this page, because there is nothing to migrate away from.&lt;/p&gt;

&lt;p&gt;What makes it genuinely reasonable is scope. Email-and-password plus perhaps one OAuth provider through a small client library: fine, and a better education than any tutorial. The moment the requirements say passkeys, organizations, or an enterprise provider list, you are rebuilding Better Auth one incident at a time. And the things you must get right are not optional:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Password hashing with argon2id, or bcrypt at a work factor of 12 or more — never a fast hash like SHA-256 for passwords, never a scheme you invented.&lt;/li&gt;
&lt;li&gt;Session rotation: issue a fresh token at login and on every privilege change, so a session fixed or leaked before sign-in is worthless afterwards.&lt;/li&gt;
&lt;li&gt;CSRF protection: SameSite cookies as the floor, plus an Origin header check on every state-changing request — SameSite alone does not cover every flow.&lt;/li&gt;
&lt;li&gt;Rate limiting on login, registration, and password-reset endpoints — credential stuffing is automated, constant, and completely indifferent to how small your app is.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice that this list is not really about DIY. It is the security baseline any option on this page must clear — real password hashing, httpOnly and Secure cookies, rate limiting on auth endpoints, and a credible path to MFA. The libraries clear different parts of it for you; none of them clears all of it. Audit whatever you pick against those four lines before launch.&lt;/p&gt;

&lt;h2&gt;
  
  
  The decision rule
&lt;/h2&gt;

&lt;p&gt;Here is the rule by scenario, in the order I would actually check the conditions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Side project or learning build: roll your own sessions, on purpose. It is the best auth education available and the failure cost is low. If the goal is shipping rather than learning, Better Auth — you will have 2FA working before your first real user asks for it.&lt;/li&gt;
&lt;li&gt;Production SaaS: Better Auth is the 2026 default — two-factor, passkeys, and organizations as configuration rather than as projects, with the schema in your own Postgres. Choose NextAuth instead if your sign-in story is OAuth-heavy or needs a long-tail provider, and you accept building MFA and lockout yourself. Already on Supabase: use its auth and spend the saved week on row-level security.&lt;/li&gt;
&lt;li&gt;Enterprise SSO: this is where hosted earns its invoice. SAML, SCIM provisioning, and compliance checkboxes are exactly the undifferentiated misery Auth0 and WorkOS exist to absorb. NextAuth can reach many of the same providers if the budget says no — but you own the configuration burden and the support calls.&lt;/li&gt;
&lt;li&gt;Whatever you pick: if the user table cannot live in your database, demand a tested export path before you write the first line of integration code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then commit properly. Spike the winner in a branch this week: one real sign-in, one protected page, and the export script from the top of this article, all working before you build a single feature on top. Auth is the layer everything else stands on. Wire it once, correctly, and it becomes the most boring part of your app for years — which is the highest compliment auth can earn.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/nextauth-vs-lucia-vs-better-auth?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=nextauth-vs-lucia-vs-better-auth"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=nextauth-vs-lucia-vs-better-auth"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>What Is Web Development? A Complete Beginner's Guide</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Mon, 16 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/codefromscratch/what-is-web-development-a-complete-beginners-guide-3ebb</link>
      <guid>https://dev.to/codefromscratch/what-is-web-development-a-complete-beginners-guide-3ebb</guid>
      <description>&lt;p&gt;You typed "what is web development" into a search box, and every answer was either a dictionary definition or an advert for a course. Today I'll give you the real map: what web development is, the three languages behind every page, what the browser does and what the server does, how a page reaches your screen, and how to start without drowning. Every piece of code here runs, and some of it you'll click yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Web development, in plain words
&lt;/h2&gt;

&lt;p&gt;Web development is building the things that run in a web browser, and the machines behind them that make those things work. The page you're reading now, your online banking, the form where you book a dentist appointment, the admin screen behind a web shop: someone wrote all of that, and writing it is web development. That's the whole definition. Everything else in this article is detail.&lt;/p&gt;

&lt;p&gt;Here's a comparison I'll keep coming back to. A website is a restaurant. The dining room is what you see: the tables, the menu, the look of the place. That's the front end, the part that runs in your browser. The kitchen is where the real work happens, out of sight: the orders, the stock, the recipes. That's the back end, the server. And the waiter who carries your order in and your food out is the connection between the two. We'll meet all three today, and we'll build a tiny version of each.&lt;/p&gt;

&lt;p&gt;How to read this. If you're starting from zero, read top to bottom, and don't skip the code, because the code is the point. If you've built a page or two and the part that confuses you is "what does the server actually do", jump to the section where we build one. If you already work as a developer and you're here to send this to someone, the parts marked "for advanced readers" are the bits I'd want a junior to hear from you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this feels so confusing when you start
&lt;/h2&gt;

&lt;p&gt;I wanted to do this since I was about twelve. An older cousin of mine went to a technical school, and watching him was enough to know what I wanted. So I went looking for material, and there's an ocean of it. Videos, courses, roadmaps with two hundred boxes. And almost nobody is direct. Nobody sits you down and says: here's what this is, here's how the pieces connect, here's where you start.&lt;/p&gt;

&lt;p&gt;Courses were the worst for this. I finished them and still felt I knew nothing. They taught me to find prime numbers in a loop and pull a name out of an array, and never once showed me where that turns up in a real website. I wrote about that whole problem in &lt;a href="https://codefromscratch.org/blog/why-courses-leave-you-feeling-like-you-know-nothing?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;why courses leave you feeling like you know nothing&lt;/a&gt;, so I won't repeat it here. The short version: you get the pieces, and nobody connects them.&lt;/p&gt;

&lt;p&gt;Why does the confusion exist at all? Because the web wasn't designed in one go. It grew. The first web pages, in the early nineties, were documents with links between them. Then people wanted them to look nice, so a language for styling was added. Then they wanted pages that react when you click, so a programming language was put into the browser. Then they wanted logins and shopping carts, so servers and databases got involved. Each layer landed on top of the last one, over thirty years, built by different people solving different problems.&lt;/p&gt;

&lt;p&gt;When you learn it the way most tutorials teach it, layer by layer, you get each piece without the reason it exists. That's the confusion. It isn't you. So let's do it the other way round: first the map, then the pieces.&lt;/p&gt;

&lt;h2&gt;
  
  
  The basics of web development: three languages, two places, one conversation
&lt;/h2&gt;

&lt;p&gt;That's the whole map, and I want you to hold on to it, because every tool you'll ever hear about fits somewhere on it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Three languages. HTML gives a page its structure: this is a heading, this is a paragraph, this is a link. CSS gives it its look: colours, spacing, fonts, where things sit. JavaScript gives it behaviour: what happens when you click, type or scroll.&lt;/li&gt;
&lt;li&gt;Two places. The browser, on the visitor's phone or laptop, is where the front end runs. The server, a computer somewhere that's always on, is where the back end runs: it keeps the data and decides what the visitor is allowed to do.&lt;/li&gt;
&lt;li&gt;One conversation. The browser asks for something, the server answers. A request, a response. Every page load, every "add to cart", every login is one of those conversations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Look, that's all it is. Three languages, two places, one conversation. When a new tool shows up, and one shows up every month, ask which part of the map it belongs to, and it stops being scary. React is a JavaScript tool for the browser. PostgreSQL is a place to keep data, next to the server. Next.js is a tool that works on both sides. Nothing escapes the map.&lt;/p&gt;

&lt;p&gt;Now let's build each piece, small enough to understand and real enough to run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: HTML, the structure. A website is a folder of files
&lt;/h2&gt;

&lt;p&gt;Here's something that surprised me early on: a website is a file. A few files, in a folder. Your browser opens them the way a music player opens a song. So let's make one. Create a folder called my-site, and inside it a file called index.html. Open it in any text editor and type this in.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;my-site/index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Emily's page&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"styles.css"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hi, I'm Emily&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;I'm learning web development, one page at a time.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://developer.mozilla.org/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;The site I read most&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every line here does a job, so let's go through them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first line, doctype html, tells the browser "this is modern HTML, use the current rules". Leave it out and browsers fall back to an old compatibility mode where some CSS behaves strangely. It costs you nothing to keep it.&lt;/li&gt;
&lt;li&gt;html lang="en" is the root element, the box that holds everything. The lang part tells screen readers how to pronounce the text and tells search engines what language the page is in.&lt;/li&gt;
&lt;li&gt;head holds information about the page. None of it is drawn on screen. The charset line makes sure letters like é display correctly. The viewport line stops phones from zooming the page out to desktop size. The title is what you see in the browser tab, and what Google shows as the headline of a search result. The link line loads our stylesheet, which we'll write next.&lt;/li&gt;
&lt;li&gt;body holds what you see. h1 is the main heading; a page should have exactly one. p is a paragraph. a is a link, and href is where it goes.&lt;/li&gt;
&lt;li&gt;The script line at the bottom loads our JavaScript. It sits at the end on purpose: by the time it runs, the heading and paragraph already exist. We'll see what breaks if you move it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A word on words. Those things in angle brackets are tags, and a tag with its content is an element. HTML is the bones of every page. If you stripped a beautiful website of all its styling and all its interactivity, what would be left is the HTML, like the framing of a house before the paint and the furniture arrive.&lt;/p&gt;

&lt;p&gt;Save the file and double-click it. Your browser opens it and shows a heading, a sentence and a link. It looks plain. That's correct. You've made a website. No, really: that file is a website. Put it on a server and anyone on earth can open it. Everything from here on is making it look better, do more, and talk to other computers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: CSS, the look
&lt;/h2&gt;

&lt;p&gt;Now create styles.css in the same folder. A CSS file is a list of rules, and each rule says the same thing: find these elements, and make them look like this.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;my-site/styles.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;system-ui&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;40rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3rem&lt;/span&gt; &lt;span class="n"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#1f2937&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#0f766e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#0f766e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;underline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;body { ... } is a rule. The word before the curly braces is the selector, the thing to find; here it's the body element, so these settings apply to the whole page. Inside the braces are declarations: a property, a colon, a value, a semicolon.&lt;/li&gt;
&lt;li&gt;font-family: system-ui, sans-serif tells the browser to use the operating system's own font, and if it can't, any font without serifs. Lists like this are fallbacks, read left to right.&lt;/li&gt;
&lt;li&gt;max-width: 40rem stops lines of text from growing wider than about 640 pixels. A rem is a unit relative to the default text size, which is 16 pixels unless the visitor changed their browser settings, so 40rem is usually 640. Long lines are hard to read; this is the single cheapest thing you can do for readability.&lt;/li&gt;
&lt;li&gt;margin: 3rem auto puts space above and below the page, and auto on the left and right splits the leftover space evenly, which centres the box. Yes, centring in CSS can be this easy. Not always, but here.&lt;/li&gt;
&lt;li&gt;padding: 0 1rem keeps the text off the screen edge on a phone. Remove it and your words will touch the glass.&lt;/li&gt;
&lt;li&gt;The h1 and a rules give the heading and the link a teal colour. The link keeps its underline on purpose: an underline is how people know something is clickable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What breaks if you delete the link line from the head of index.html? Nothing errors. The page goes back to the browser's defaults: black text, the default serif font, full width. CSS never breaks a page. It just stops dressing it. That's the whole relationship: HTML is the person, CSS is the clothes. Same person, different outfit.&lt;/p&gt;

&lt;p&gt;If you want to build a complete page this way, with a proper layout and the box model explained, &lt;a href="https://codefromscratch.org/blog/html-css-beginners-build-first-web-page?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;the HTML and CSS beginner guide&lt;/a&gt; walks you through a real one from an empty folder, and &lt;a href="https://codefromscratch.org/blog/css-flexbox-vs-grid-real-layouts?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;flexbox versus grid&lt;/a&gt; shows you how to arrange things once you've got more than a few on the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: JavaScript, the behaviour
&lt;/h2&gt;

&lt;p&gt;Now the third file, script.js. HTML and CSS describe a page. JavaScript lets the page do something. Here's the smallest useful example I know: a heading that counts how often you click it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;my-site/script.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"h1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;clicks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"click"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;clicks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;clicks&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"You clicked me "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;clicks&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;" times"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;document.querySelector("h1") searches the page for the first h1 element and hands it back. We store it in a constant called heading, so we've got a handle on that element, like a remote control for it.&lt;/li&gt;
&lt;li&gt;let clicks = 0 creates a variable: a named box that holds a value, starting at zero. let means the value can change later. const, on the line above, means it can't.&lt;/li&gt;
&lt;li&gt;heading.addEventListener("click", ...) says: when a click happens on this heading, run the function that follows. An event is anything that happens on the page: a click, a key press, the page finishing loading. Listening for events is most of what front-end JavaScript does.&lt;/li&gt;
&lt;li&gt;The part in parentheses with the arrow is the function: a block of code waiting to be run. It adds one to clicks, then replaces the text inside the heading with a new sentence. textContent is the text between the tags, and setting it changes the page immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reload the page and click the heading. "You clicked me 1 times". Click again: 2. Nothing reloaded. The page changed itself. That's what JavaScript is for, and that's the feeling you're chasing for the first few weeks: a page that reacts.&lt;/p&gt;

&lt;p&gt;Yes, "1 times" is bad grammar. Leave it in. It's a good first bug to fix on your own, and the fix is an if statement, which you'll learn in your first week.&lt;/p&gt;

&lt;p&gt;Now the promised breakage. Move the script line from the bottom of the body up into the head, reload, and click the heading. Nothing happens. Open the browser's console (press F12) and you'll see an error that every web developer has met: Cannot read properties of null (reading 'addEventListener'). The browser reads your file from top to bottom. In the head, the script ran before the heading existed, so querySelector found nothing and returned null, and you can't add a listener to nothing. Order matters, and now you know why.&lt;/p&gt;

&lt;h2&gt;
  
  
  All three together, live
&lt;/h2&gt;

&lt;p&gt;Here's a small page you can use right now, inside this article. Type a name and press the button. Click the counter. Then open the HTML, CSS and JavaScript tabs and read the source: it's the same three languages doing the same three jobs as in our folder, just on one page.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; All three languages on one page. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/what-is-web-development-beginners-guide?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A few things in there are worth a closer look, because they come up in every real form you'll ever build.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the HTML, the label has for="name" and the input has id="name". That pairs them: clicking the label focuses the input, and a screen reader announces "Your name" when the input is selected. The button has type="submit", so pressing Enter in the input submits the form too. The counter button has type="button", so it doesn't.&lt;/li&gt;
&lt;li&gt;The answer paragraph has aria-live="polite". That asks screen readers to read out the greeting when it appears, without interrupting. One attribute, and the page works for people who can't see it.&lt;/li&gt;
&lt;li&gt;In the CSS, display: flex on the form puts the label, input and button in one row, gap is the space between them, and flex-wrap lets them drop onto a second row on a narrow phone. The rest is colour and padding.&lt;/li&gt;
&lt;li&gt;In the JavaScript, the form listens for the submit event. The first line inside it, event.preventDefault(), stops the browser from doing its default thing, which is to send the form to a server and reload the page. We've got no server yet, so we handle it ourselves. trim() removes spaces from both ends of what was typed, and if nothing is left, we show a message and stop with return. Otherwise we build the greeting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Take preventDefault out in your head: the page would reload and the greeting would vanish before you could read it. That one line is the difference between "the page reacts" and "the page restarts". You'll write it in every form you ever make.&lt;/p&gt;

&lt;p&gt;One honest note. This demo checks the name in your browser only. In a real app, anything that matters is checked again on the server, because the browser belongs to the visitor, not to you, and anyone can change what it sends. That idea is big enough to get its own article: &lt;a href="https://codefromscratch.org/blog/login-form-validation-client-and-server?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;why you check a login form twice&lt;/a&gt;. For now, just remember: the browser is the dining room. You don't let guests into the kitchen.&lt;/p&gt;

&lt;h2&gt;
  
  
  How a page reaches your screen
&lt;/h2&gt;

&lt;p&gt;Now the conversation. You type codefromscratch.org into the address bar and press Enter. In the half second before the page appears, this happens.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Address lookup. Your browser asks the Domain Name System, DNS, for the numeric address of codefromscratch.org. DNS is a phone book: you know the name, it gives you the number. Computers talk to numbers, not names.&lt;/li&gt;
&lt;li&gt;Connection. The browser opens a connection to that number. With https, the connection is encrypted first, which is what the padlock in the address bar means: nobody between you and the server can read what passes through.&lt;/li&gt;
&lt;li&gt;Request. The browser sends a short message in a format called HTTP: "GET /blog/what-is-web-development-beginners-guide". GET means "give me", and the path says which page.&lt;/li&gt;
&lt;li&gt;Response. The server reads the request, maybe asks a database for the article, builds the HTML and sends it back with a status code. 200 means "here you go".&lt;/li&gt;
&lt;li&gt;Rendering. The browser reads the HTML, notices it references a stylesheet and some scripts, asks for those too, and then draws the page. JavaScript runs, and the page becomes interactive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those five steps are the version MDN teaches in &lt;a href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Getting_started/Web_standards/How_the_web_works" rel="noopener noreferrer"&gt;How the web works&lt;/a&gt;, with a few more details if you want them. Steps one to three are plumbing; you'll learn enough to understand them, and you don't need to become a network engineer. Step four is the back end. Step five is the front end. The whole industry lives in those two.&lt;/p&gt;

&lt;p&gt;You can watch two of these steps yourself. Open a terminal, the black window with text, and type this.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nslookup codefromscratch.org
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The answer looks something like "Addresses: 64.29.17.1, 216.198.79.1". Two numbers, because hosting companies answer from more than one machine, and the numbers can change over time. That's step one, done by hand. Now step three and four.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -I https://codefromscratch.org/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;output (shortened)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;HTTP/1.1 200 OK
Content-Type: text/html&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;utf-8
Server: Vercel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;curl is a tool that sends requests without a browser, and -I asks for the headers only: the envelope, not the letter. The first line is the status, 200 OK. Content-Type tells the browser what kind of thing it's getting, here an HTML page. Server tells you who answered. Try the same command with a page that doesn't exist, like codefromscratch.org/nothing-here, and the first line becomes 404 Not Found. Status codes are the server's one-word answers: 200 fine, 404 no such page, 500 I broke something. You'll meet all three.&lt;/p&gt;

&lt;p&gt;When you buy your own domain one day and wonder why it doesn't point at your site yet, that's step one again, and &lt;a href="https://codefromscratch.org/blog/domain-ssl-email-dns-setup?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;the domain, SSL and DNS guide&lt;/a&gt; walks through it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: the server, a kitchen you can build in twelve lines
&lt;/h2&gt;

&lt;p&gt;Time for the other side. A server sounds like a big machine in a cold room, and sometimes it is, but the word also means something simpler: a program that waits for requests and answers them. It runs on a computer that's always on. On your laptop it works exactly the same way, except only you can reach it.&lt;/p&gt;

&lt;p&gt;We'll write it in JavaScript, which needs one more piece. JavaScript was born inside the browser. Node.js is JavaScript running outside the browser, as an ordinary program on your computer. That's why most beginner paths use it for the server: one language on both sides, nothing new to learn except the server idea itself.&lt;/p&gt;

&lt;p&gt;Install it from &lt;a href="https://nodejs.org/en/about/previous-releases" rel="noopener noreferrer"&gt;nodejs.org&lt;/a&gt; and take the version marked LTS, which stands for long-term support: the one that gets fixes for years. As I write this, at the end of October 2026, Node 26 has just become the newest LTS line, and the Node team's own advice on that page is that production applications use only LTS releases. The examples here were run on Node 24, the previous LTS, and nothing in them is version-specific.&lt;/p&gt;

&lt;p&gt;Now, in a new folder, create server.mjs. The .mjs ending tells Node the file uses the modern import syntax; name it .js and Node still runs it, but prints a warning about guessing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;server.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;createServer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:http"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"/api/greeting"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Hello from the server"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Not found"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4321&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Listening on http://localhost:4321"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;import { createServer } from "node:http" pulls in the function we need from a module that ships with Node. Nothing to install. The node: prefix says it's a built-in.&lt;/li&gt;
&lt;li&gt;createServer takes a function and runs it once for every request that arrives. The function gets two objects: request, which holds what the browser asked for, and response, which we fill in with our answer.&lt;/li&gt;
&lt;li&gt;if (request.url === "/api/greeting") checks which path was asked for. For that one path, we set a header saying "the body is JSON", write the body with response.end, and return so the code below doesn't run as well.&lt;/li&gt;
&lt;li&gt;For any other path, we set the status to 404 and answer "Not found". Every server needs an answer for the unexpected; this is yours.&lt;/li&gt;
&lt;li&gt;server.listen(4321, ...) starts waiting for requests on port 4321. A port is a numbered door on your computer. The browser knocks on door 4321, and this program answers. The function after it runs once, when the door is open, and prints the address.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start it and ask it something. Two terminals: one to run the server, one to be the browser.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal 1&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node server.mjs
&lt;span class="c"&gt;# Listening on http://localhost:4321&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;terminal 2&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -i http://localhost:4321/api/greeting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;output&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;HTTP/1.1 200 OK
Content-Type: application/json

&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;:&lt;span class="s2"&gt;"Hello from the server"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;localhost means "this computer". The -i flag shows the headers and the body together. And the body is JSON: a text format for data that both sides understand, which looks like a JavaScript object with quotes around the names. It's how the kitchen passes plates to the waiter. Almost every server you'll ever talk to speaks it.&lt;/p&gt;

&lt;p&gt;Now the browser side of the same conversation. Three lines.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;client.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"http://localhost:4321/api/greeting"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;fetch(...) sends a request to that address, the same GET our browser sent earlier. It returns a promise, a placeholder for an answer that isn't here yet, and await pauses this code until the answer arrives. Like ordering and sitting down, instead of standing at the counter frozen.&lt;/li&gt;
&lt;li&gt;response.json() reads the body and turns the JSON text into a real object. It also takes a moment, so it also gets an await.&lt;/li&gt;
&lt;li&gt;data.message is the value we put in on the server. Printed, it says "Hello from the server". Same words, other side of the counter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run it with node client.mjs while the server is up, and you'll see the greeting. The same three lines work inside a web page, in the browser, as long as the page came from the same server; a page from one site asking another site's server gets blocked by the browser unless that server allows it, a rule called CORS that you'll meet later and curse once.&lt;/p&gt;

&lt;p&gt;So that's all it is. A server is a program that answers questions. The browser never walks into the kitchen; it asks the waiter, and a plate comes back. Everything you'll ever build on the back end, logins, carts, dashboards, is this loop with more rules about who may ask for what.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For advanced readers: a real back end is a framework on top of this same idea (Express, Hono, or Next.js route handlers) with a database behind it. The shape never changes: request in, response out. What changes is the part that matters in production: who is allowed to ask (authentication), what they're allowed to get (authorization), how often (rate limits), and what happens when the database is down. Beginners can ignore all of that today. Nobody shipping to real users can.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And the database? It's the storeroom behind the kitchen: the place where accounts, orders and articles live so they survive the server restarting. PostgreSQL is the safe default for most new projects. How you talk to one from JavaScript is a topic of its own, covered in &lt;a href="https://codefromscratch.org/blog/prisma-orm-from-zero-to-production?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;Prisma from zero to production&lt;/a&gt;, and the full picture of how every layer of a modern app fits together is in &lt;a href="https://codefromscratch.org/blog/modern-full-stack-2026?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;modern full-stack development, explained end to end&lt;/a&gt;. Read those later, not now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Front end, back end, full stack: what the job titles mean
&lt;/h2&gt;

&lt;p&gt;You'll see job adverts for front-end developers, back-end developers and full-stack developers. Now you can translate them.&lt;/p&gt;

&lt;p&gt;Front-end developers work in the browser. They care about layout, how a button feels under a thumb on a cheap phone, whether the page works for someone using a screen reader, and whether it loads fast on a bad connection. Back-end developers work on the server. They care about data, correctness and security, and about what happens when ten thousand people press the same button in the same second. Full-stack developers do both to a usable level. Most freelancers and people on small teams end up there out of necessity: when a local shop asks you for a website, it has to work end to end, not just look nice.&lt;/p&gt;

&lt;p&gt;You'll also hear names of tools, so here's where they sit on the map. React is a JavaScript library for building the browser side out of reusable pieces called components. Next.js is a framework around React that also runs on the server; this site is built with it. Vue and Svelte do the same job as React with different ideas about how. On the server side, JavaScript with Node is one option. Python, with frameworks like Django or FastAPI, is another. PHP still runs a huge slice of the web through WordPress, which the statistics company W3Techs counted on about 39.5 percent of all websites in October 2026. Go and Ruby are there too. All of them fit the map. None of them need picking today.&lt;/p&gt;

&lt;p&gt;Source for the WordPress figure: &lt;a href="https://w3techs.com/technologies/overview/content_management" rel="noopener noreferrer"&gt;W3Techs, usage of content management systems&lt;/a&gt;. Treat it as a survey, not a law of nature.&lt;/p&gt;

&lt;p&gt;Where this blog stands: most of what I write uses JavaScript on both sides, with Next.js, because it's what I work with as a web developer, and because one language first is kinder to a beginner than two. That's a preference, not a verdict. The map is the same in every language.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools you'll meet in the first month
&lt;/h2&gt;

&lt;p&gt;You don't need a powerful computer, a paid program or a particular brand of laptop. Here's what shows up on day one and stays with you for the rest of your career.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A code editor. VS Code is free and is what most working developers use. It colours your code, points out typos, and has an extension for everything.&lt;/li&gt;
&lt;li&gt;A browser with developer tools. Chrome, Firefox, Edge or Safari, they all have them. Press F12 (or Cmd+Option+I on a Mac) and a panel opens that lets you inspect any page on earth, see its HTML, change its CSS live, and read the errors your JavaScript throws. You'll live in it.&lt;/li&gt;
&lt;li&gt;Git and GitHub. Git keeps every version of your files so you can undo anything; GitHub is where you store and share them. Learn the five basic commands in week one. Future you will be grateful.&lt;/li&gt;
&lt;li&gt;Node.js and npm. Node runs JavaScript outside the browser, as you saw. npm, which comes with it, installs code other people wrote so you don't have to write it yourself.&lt;/li&gt;
&lt;li&gt;A terminal. The text window. Scary for a week, useful forever. About ten commands cover the first year.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Total cost to start: zero. Any laptop from the last several years is fine.&lt;/p&gt;

&lt;p&gt;And then there's AI. You'll be tempted to let an AI tool write all of it, and you'll see people online who build whole apps that way without understanding a line. I use AI tools a lot in my work, and I check what they write as far as I can, because they make mistakes without meaning to, and they assume things they shouldn't. Here's the honest rule: AI is good at typing code and bad at knowing what should be typed. If you don't understand the three languages and the conversation, you can't tell when it's wrong, and it will be wrong, and the first bug you can't read will stop you cold. Learn the map first. Then AI becomes a fast colleague instead of a mystery box, and you become the person who directs it, which is where this job is going.&lt;/p&gt;

&lt;h2&gt;
  
  
  Beginning web development: what to learn, in what order
&lt;/h2&gt;

&lt;p&gt;I'm not going to give you "become a developer in 30 days". I don't have an honest number, and anyone who gives you one is selling something. What I can give you is the order, because the order is where most people go wrong.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, HTML and CSS, on a page that is yours. About you, your dog, your football team, your favourite recipes. Then find a simple page you like online and rebuild it by hand, without a template. You'll be slow and you won't always know why something works. Repetition is the teacher here.&lt;/li&gt;
&lt;li&gt;Second, JavaScript, by making your page react. A dark-mode toggle. A counter. A list you can add things to. Expect to relearn functions, events and the difference between an array and an object three or four times before they stick. That is normal. People who are good at this now were confused at this exact point.&lt;/li&gt;
&lt;li&gt;Third, one real small project, finished. Not five started. Pick something you'd use yourself and take it to done, ugly if necessary. Finishing is a skill, and it's the one that courses never train.&lt;/li&gt;
&lt;li&gt;Fourth, the conversation. A tiny server like the one above, a form that sends to it, and data that survives a restart. The day a form on your page writes a row into a database is the day it all clicks.&lt;/li&gt;
&lt;li&gt;Fifth, and only now, a framework such as React or Next.js. People who jump to React in week two get lost, because a framework hides the JavaScript under it and they never learned what's being hidden.&lt;/li&gt;
&lt;li&gt;Sixth, put something online with a real address and show it to a real person. That's when it stops being an exercise.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you reach step six, &lt;a href="https://codefromscratch.org/blog/ship-nextjs-production?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;shipping a Next.js app to production&lt;/a&gt; covers the whole move from your laptop to a real URL. Bookmark it, don't read it yet.&lt;/p&gt;

&lt;p&gt;On pace. You'll read "study two or three hours every day". I think that's bad advice for a beginner. Some days code goes in and some days it doesn't. You get sick, you have moods, life happens. Take a day or two off rather than get sick of the whole thing. But don't take long breaks or frequent ones either, because then no habit forms and you forget what you learned. A little, most days. One percent a day over a year beats a heroic weekend followed by a month off.&lt;/p&gt;

&lt;p&gt;And if you're starting late, or starting over: I had to restart my education from the beginning in a new country, in a language I didn't speak yet. It was a detour, and detours are fine. If you love this enough to come back to it on evenings and weekends, you'll get there. That's not advice to overwork, and I'll keep saying so. It's advice to keep going.&lt;/p&gt;

&lt;h2&gt;
  
  
  Myths, corrected
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;"You need to be good at maths." You need to be good at logical thinking. The maths behind most of the web is adding, multiplying and percentages. Game engines and 3D graphics are the exception, and you're not starting there.&lt;/li&gt;
&lt;li&gt;"It's too late to start at 30 or 40 or 50." Your previous career is an advantage. People who can talk to clients, write clearly and run a project are rarer in this field than people who can code.&lt;/li&gt;
&lt;li&gt;"AI will replace developers." AI changes how the work is done, less typing and debugging, more directing and checking. The people who fall behind are the ones who never learn to check. Whoever lags falls behind fast, because AI moves fast. Learn the map and you're ahead of most of the room.&lt;/li&gt;
&lt;li&gt;"You need to learn everything before you start." You need to learn enough to build one small thing, then the next thing as you build the next small thing. Nobody knows the whole field, and many people working in companies don't know everything and need help every week. That's normal. Not knowing yet is fine.&lt;/li&gt;
&lt;li&gt;"You need a degree." You need a browser, an editor and the patience to ship things that look bad before they look good. Study if you can, it helps. It isn't the gate.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to be careful about, and the Plan B
&lt;/h2&gt;

&lt;p&gt;Here's what I'd tell myself at the start, because I got every one of these wrong. For a long time I built things from my head until I liked how they looked. No plan, no sketch, no thought about which tags I was using, whether anyone would ever find the site, or whether the people using it were safe. All of that caught up with me later.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Plan before you type. Even a sketch on paper. Decide what the page is for and what's on it, then build. "From my head until it looks good" works right up until it doesn't.&lt;/li&gt;
&lt;li&gt;Use the right tags, not just div for everything. Screen readers and search engines read your HTML, not your screen. A heading should be an h1, a list a ul, a button a button.&lt;/li&gt;
&lt;li&gt;Think about being found. The best content on earth is invisible if a search engine never shows it. I didn't think SEO mattered. It does, and it starts with a good title and clean HTML, which you now have.&lt;/li&gt;
&lt;li&gt;Never trust the browser. Anything that matters, prices, permissions, passwords, is checked on the server. The front end is the dining room; the rules live in the kitchen.&lt;/li&gt;
&lt;li&gt;Don't just watch. Tutorials you only watch leave nothing behind. Type every example, break it on purpose, fix it.&lt;/li&gt;
&lt;li&gt;Don't ship what you can't explain. If an AI wrote it and you can't say what each line does, you don't own it yet. Ask it to explain, then check the explanation. I wrote a separate piece on &lt;a href="https://codefromscratch.org/blog/learn-web-development-from-scratch-with-ai?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;learning web development with AI&lt;/a&gt;: what to learn yourself and what to hand off.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the Plan B for when you're stuck, because you will be. First, read the error message out loud, word by word. It's usually telling the truth, like our null error above. Second, make the smallest possible page that still shows the problem; half the time the bug reveals itself while you shrink it. Third, search the exact text of the error. Fourth, ask someone. Write to me if you like. I mean that. Being stuck for an hour is learning. Being stuck for a week alone is how people quit.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; For advanced readers who mentor beginners: the most useful thing you can give someone is the map above and one real project, not a list of technologies to learn. The list is what made them feel they knew nothing in the first place. And when you review their code, explain why, every time. The why is what they can't get from a tutorial.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  So that's all it is
&lt;/h2&gt;

&lt;p&gt;Three languages: HTML for structure, CSS for the look, JavaScript for behaviour. Two places: the browser and the server. One conversation: request, response. You built a page, styled it, made it react, watched a request with your own eyes, and wrote a server that answered one. That's not an introduction to web development. That's web development, small.&lt;/p&gt;

&lt;p&gt;What next, in order. Build your first real page with &lt;a href="https://codefromscratch.org/blog/html-css-beginners-build-first-web-page?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;the HTML and CSS beginner guide&lt;/a&gt;. When you've got more than a few things to arrange, read &lt;a href="https://codefromscratch.org/blog/css-flexbox-vs-grid-real-layouts?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;flexbox versus grid on real layouts&lt;/a&gt;. When your first form is ready, read &lt;a href="https://codefromscratch.org/blog/login-form-validation-client-and-server?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;why you check a login form twice&lt;/a&gt; and you'll see the conversation from both sides. Much later, when something of yours has real users, &lt;a href="https://codefromscratch.org/blog/production-grade-code-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;the production-grade code checklist&lt;/a&gt; is the list of habits that keep them safe.&lt;/p&gt;

&lt;p&gt;You can do this, and you have to. If you weren't capable, I wouldn't spend my time on you. Just don't give up, and you'll always have me on your side.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/what-is-web-development-beginners-guide?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=what-is-web-development-beginners-guide"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>html</category>
      <category>css</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Build a Sticky Header and Hero Section From Scratch</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Sun, 15 Nov 2026 19:00:00 +0000</pubDate>
      <link>https://dev.to/codefromscratch/build-a-sticky-header-and-hero-section-from-scratch-oip</link>
      <guid>https://dev.to/codefromscratch/build-a-sticky-header-and-hero-section-from-scratch-oip</guid>
      <description>&lt;p&gt;You open almost any modern website and the same two things greet you: a header with a logo and a few links that stays at the top while you scroll, and a big first section with a headline and one button. Today we build both from scratch, with our own text and colours, and I'll show you why a sticky header so often refuses to stick, how the header that hides on the way down and comes back on the way up really works, and how to make the first screen hold on a phone.&lt;/p&gt;

&lt;p&gt;Here's the short answer first. A sticky header is a normal header with position: sticky and top: 0, placed where its parent is as tall as the page and no parent has overflow: hidden. The hide-on-scroll trick is a small script that compares the current scroll position with the last one and adds a class that slides the header up with a transform. The hero uses min-height with the svh unit, never a fixed height, and a font size built with clamp().&lt;/p&gt;

&lt;p&gt;If you're a beginner, read it from the top and click both live demos, because seeing a header that refuses to stick teaches more than any definition. If you already build layouts every day, jump to the section on why the header doesn't stick and then to the scroll script. Those are the places where people who know the basics still lose an afternoon. The parts about focus, reduced motion and short screens are for everyone who ships to real users.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Tested with: Chrome 156 (headless) on 2026-11-13, at 760, 375 and 320 pixels wide. Every demo and snippet in this article was run there and the numbers I mention, like header heights and font sizes, come from those runs. Safari and Firefox were not tested for this article, so click the demos in your own browser too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why we rebuild a header everyone has already seen
&lt;/h2&gt;

&lt;p&gt;This article is part of a series I call Concepts in practice. Instead of learning CSS properties one by one from a list, we take a piece of a website you already know from daily life, rebuild it, and look at the tricks behind it. You learn faster when you already know what the finished thing should look like.&lt;/p&gt;

&lt;p&gt;The header and the hero are the first two things on nearly every landing page, shop and app. They look simple. A strip with a logo and three links, then a big title. And yet they're where a lot of beginner sites quietly fall apart: the header that sticks on the laptop but not in the real project, the anchor link that lands with the heading hidden under the header, the hero that's cut off on a phone because of the address bar.&lt;/p&gt;

&lt;p&gt;By the end you'll have built a page that does four things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The header stays at the top of the screen while you scroll.&lt;/li&gt;
&lt;li&gt;It slides away when you scroll down to read, and comes back the moment you scroll up a little.&lt;/li&gt;
&lt;li&gt;It never hides the heading you jumped to or the link you're focused on with the keyboard.&lt;/li&gt;
&lt;li&gt;The first section fills the screen on a laptop and on a phone, without cutting anything off.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Rebuild the pattern, never the brand. A sticky header belongs to nobody. A company's logo, wording, photos and colours do belong to someone. Everything in this article, from the bakery name to the colours, is made up. Do the same when you practise, and especially before anything you build goes on a public page.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A sticky header is a normal element with one extra rule
&lt;/h2&gt;

&lt;p&gt;Let's get the words straight first. The header is the strip at the top of a page with the logo and the main links. The hero is the first big section under it: a headline, one or two lines of text and usually one button. And sticky is a value of the CSS position property that makes an element scroll normally until it reaches a line you choose, and then stay on that line.&lt;/p&gt;

&lt;p&gt;Here's a comparison from normal life. Think of a fridge magnet on a sheet of paper you're sliding up the fridge door. The magnet moves with the paper until it hits the top edge of the door, and then it stays there while the paper keeps sliding. But it can never leave the paper. When the bottom of the sheet arrives, the magnet goes with it. That last part matters, and it's the reason most broken sticky headers are broken.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/position" rel="noopener noreferrer"&gt;MDN reference for position&lt;/a&gt; puts it more formally: a sticky element is treated as relatively positioned until its containing block crosses a threshold, such as top set to something other than auto, and then it's treated as stuck "until meeting the opposite edge of its containing block". The containing block is, for our purposes, the parent. That's the sheet of paper.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why I reach for sticky and not fixed
&lt;/h3&gt;

&lt;p&gt;You'll also see position: fixed used for headers. A fixed element is glued to the screen from the start, no matter where its parent is. That sounds simpler, so why not use it?&lt;/p&gt;

&lt;p&gt;Because a fixed element is taken out of the page. The browser stops reserving space for it, so the first lines of your content slide underneath it. The usual fix is to add padding to the top of the body equal to the header's height. That works until the header's height changes, and it changes more often than you'd think. In the demo later in this article the header is 56 pixels tall on a laptop and 69 pixels tall on a 375 pixel phone, because the links wrap onto a second line. A fixed padding would be wrong on one of the two.&lt;/p&gt;

&lt;p&gt;A sticky header keeps its place in the page. Its space stays reserved, nothing slides under it at the top, and if it grows, the page simply moves down. Fixed still has its uses, like a chat button in the corner, but for a header, sticky is the better default.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why your sticky header doesn't stick
&lt;/h2&gt;

&lt;p&gt;Here's the thing. Almost every complaint about sticky comes down to three causes, and none of them is a browser bug. The demo below has a small scrolling box with a header inside. Pick a version from the list, then scroll inside the box. The first version works. The other three break in the three most common ways.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; Why a sticky header stops sticking. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/sticky-header-hero-from-scratch?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=sticky-header-hero-from-scratch"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The script in this demo only swaps the markup inside the box when you pick a version. The interesting part is the difference between the four strings in the versions object, so let's go through them.&lt;/p&gt;

&lt;h3&gt;
  
  
  The parent is only as tall as the header
&lt;/h3&gt;

&lt;p&gt;In the second version the header sits inside an extra div, and that div contains nothing else. So the div is exactly as tall as the header. Remember the magnet: it can only move inside its sheet of paper. Here the paper is the size of the magnet, so there is nowhere to move. The header is technically sticky, it just has zero room to do it.&lt;/p&gt;

&lt;p&gt;This happens all the time in component frameworks, where a header component gets wrapped in a div by a layout file or a provider without you noticing. The fix is to make the header a direct child of something as tall as the page, usually the body, or to put the sticky rule on the wrapper instead of on the header.&lt;/p&gt;

&lt;h3&gt;
  
  
  A parent has overflow: hidden
&lt;/h3&gt;

&lt;p&gt;In the third version the wrapper contains the whole page, so it's tall enough. But it has overflow: hidden. MDN describes exactly this case: a sticky element sticks to its nearest ancestor that has a "scrolling mechanism", which is created when overflow is hidden, scroll, auto or overlay, "even if that ancestor isn't the nearest actually scrolling ancestor". Your header is now sticky inside a box that never scrolls. So it never sticks. You can read the note yourself in the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/position" rel="noopener noreferrer"&gt;position reference&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Why would anyone put overflow: hidden on a page wrapper? Usually to kill a horizontal scrollbar. Something on the page is a few pixels too wide, the page wobbles sideways on a phone, and overflow-x: hidden makes the wobble go away. And here's the part most people miss: you set only overflow-x, but the browser computes overflow-y as auto. In the test for this article, the wrapper reported "hidden auto". So a rule that looks like it only deals with sideways scrolling quietly turns the wrapper into a vertical scroll container too, and your sticky header dies.&lt;/p&gt;

&lt;p&gt;The fix is overflow-x: clip. The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/overflow" rel="noopener noreferrer"&gt;overflow reference&lt;/a&gt; says that with clip "the element box is not a scroll container", which is exactly what we need. It still cuts off whatever pokes out sideways, but it doesn't create a scrolling mechanism. In the same test, the wrapper with clip instead of hidden kept the header at the top.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;styles.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.page-wrapper&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;overflow-x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;clip&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;.page-wrapper is whatever element wraps your page. Use your own class name.&lt;/li&gt;
&lt;li&gt;overflow-x: clip cuts off anything wider than the wrapper, like overflow-x: hidden does, but the wrapper does not become a scroll container, so a sticky child inside it keeps working.&lt;/li&gt;
&lt;li&gt;If you remove this rule completely, the horizontal wobble comes back. The better long-term fix is to find the element that's too wide, but clip is a safe patch while you look.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One more result from that test: overflow-x: hidden on the body alone did not break the header in Chrome, because the browser hands the body's overflow over to the window in that case. On any wrapper div, it did. Don't rely on the body exception. Use clip and you don't have to remember it.&lt;/p&gt;

&lt;h3&gt;
  
  
  No top value
&lt;/h3&gt;

&lt;p&gt;The fourth version is the simplest mistake. The header has position: sticky but no top. Sticky needs to know where the line is. Without top, or another inset like bottom, there is no line, and the element behaves like a normal relatively positioned box. MDN says it in one sentence: at least one inset property needs to be set. Add top: 0 and it works.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; When a sticky element won't stick, don't stare at its own CSS. Walk up its parents. Open the browser's DevTools, go to the Console tab, and paste the small script below. It lists every ancestor that has an overflow value which creates a scrolling mechanism. Very often, the culprit is in that list.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;DevTools console&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".site-header"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parentElement&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getComputedStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;overflowX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;overflowY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s2"&gt;"visible"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s2"&gt;"clip"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;overflowX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;overflowY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parentElement&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The first line starts at the header's parent, because the header's own overflow doesn't matter here.&lt;/li&gt;
&lt;li&gt;getComputedStyle(el) returns the final values the browser uses, after every stylesheet has had its say. That's important, because the rule that breaks you might live in a file you never opened.&lt;/li&gt;
&lt;li&gt;We check overflowX and overflowY separately, because as we just saw, setting one changes the other.&lt;/li&gt;
&lt;li&gt;visible and clip are the two values that do not create a scrolling mechanism, so anything else gets logged.&lt;/li&gt;
&lt;li&gt;el.parentElement walks one level up each time, until there are no more parents and the loop ends at the html element.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run on the broken version of the bakery page, it printed one line: the page wrapper, with "hidden auto". That's your answer in a second instead of an afternoon.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: the HTML comes before any CSS
&lt;/h2&gt;

&lt;p&gt;I'll be honest about why I start here. When I started, I built pages from my head until they looked good. No plan, no thought for semantics, no thought for people using a keyboard or a screen reader. A header was a div with some links in it. It looked fine, and it was wrong in ways I couldn't see. So now the structure comes first, and the styling comes after.&lt;/p&gt;

&lt;p&gt;If HTML elements are new to you, read &lt;a href="https://codefromscratch.org/blog/html-css-beginners-build-first-web-page?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=sticky-header-hero-from-scratch"&gt;HTML and CSS From Scratch: Build Your First Web Page&lt;/a&gt; first and come back. Here's the skeleton of our page:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"skip"&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"#main"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Skip to content&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;header&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"site-header"&lt;/span&gt; &lt;span class="na"&gt;data-header&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"logo"&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"#top"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Harbor Lane Bakery&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;nav&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Main"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"#menu"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Menu&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"#visit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Visit&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"#order"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Order&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;main&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"main"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hero"&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"top"&lt;/span&gt; &lt;span class="na"&gt;aria-labelledby&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hero-title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hero-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hero-title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Fresh bread, baked before you wake up&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Sourdough, rye and cinnamon rolls from one small oven. Order by 8 pm, pick up at 7 am.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"#order"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Order for tomorrow&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The first link, "Skip to content", is for keyboard users. It's the first thing they reach with the Tab key, and it jumps straight past the header to the main content. In the full demo it's hidden above the screen until it receives focus.&lt;/li&gt;
&lt;li&gt;&amp;lt;header&amp;gt; tells the browser and screen readers that this is the page's header. A div would look the same and say nothing.&lt;/li&gt;
&lt;li&gt;data-header is a hook for our script later. I keep JavaScript hooks in data attributes so that renaming a CSS class can never break the script.&lt;/li&gt;
&lt;li&gt;&amp;lt;nav aria-label="Main"&amp;gt; marks the links as navigation and gives the area a name. A screen reader user can then jump to "Main navigation" directly.&lt;/li&gt;
&lt;li&gt;The links are a list, because they are a list. Screen readers announce "list, 3 items", which tells the user how much is coming.&lt;/li&gt;
&lt;li&gt;&amp;lt;main id="main"&amp;gt; holds the page's main content and is the target of the skip link.&lt;/li&gt;
&lt;li&gt;The hero is a &amp;lt;section&amp;gt; with aria-labelledby pointing at the h1, so the section is named by its own headline.&lt;/li&gt;
&lt;li&gt;There is exactly one h1 on the page, in the hero. The bakery name in the header is a link, not a heading.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice that the header is a direct child of the body. Not wrapped in a div, not inside main. That one decision removes the first cause of a non-sticking header before we've written a single line of CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: make it stick, and stop it covering your headings
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;styles.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;--header-h&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;3.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;scroll-padding-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--header-h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.site-header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sticky&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.25rem&lt;/span&gt; &lt;span class="mi"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--header-h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5rem&lt;/span&gt; &lt;span class="mi"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#fffaf3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1px&lt;/span&gt; &lt;span class="n"&gt;solid&lt;/span&gt; &lt;span class="mh"&gt;#e8dccb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go through it from the top.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;--header-h is a CSS variable, a named value we can reuse. 3.5rem is 56 pixels at the default font size. We need the header's height in two other places, and a variable means we change it once.&lt;/li&gt;
&lt;li&gt;scroll-padding-top on html tells the browser: when you scroll something into view, for example after a click on #visit, leave this much room at the top. We leave the header's height plus 1rem of breathing space.&lt;/li&gt;
&lt;li&gt;position: sticky and top: 0 are the two lines that make it stick. top: 0 is the line from the magnet comparison: stick when the header's top edge reaches the top of the screen.&lt;/li&gt;
&lt;li&gt;z-index: 10 keeps the header above the content that scrolls under it. Remove it and some elements, like images or anything with its own position, will slide over your header instead of under it.&lt;/li&gt;
&lt;li&gt;display: flex with justify-content: space-between puts the logo on the left and the links on the right. flex-wrap: wrap lets the links drop onto a second line on a narrow phone instead of squeezing.&lt;/li&gt;
&lt;li&gt;gap: 0.25rem 1rem is a small vertical gap and a bigger horizontal gap, for when the links wrap.&lt;/li&gt;
&lt;li&gt;min-height, not height. The header can grow when the links wrap or when someone zooms the text. A fixed height would cut the text off.&lt;/li&gt;
&lt;li&gt;background is not decoration here. Without it the header is transparent, and the text scrolling underneath shows through the links. It's the most common first-try bug after the missing top.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The scroll-padding line deserves a closer look, because it fixes something most tutorials skip. Without it, a click on an anchor link scrolls the heading to the very top of the screen, which is exactly where your sticky header sits. The heading ends up hidden behind it. The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding-top" rel="noopener noreferrer"&gt;scroll-padding-top reference&lt;/a&gt; describes it as a way to exclude regions of the scrollport "that are obscured by other content (such as fixed-positioned toolbars or sidebars)". That's our header.&lt;/p&gt;

&lt;p&gt;It also matters for accessibility. When someone moves through a page with the Tab key, the browser scrolls each focused link into view, and the same padding keeps it from landing behind the header. WCAG 2.2, the accessibility web's main accessibility standard, has a level AA rule for this called &lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/focus-not-obscured-minimum.html" rel="noopener noreferrer"&gt;Focus Not Obscured (Minimum)&lt;/a&gt;: a focused element must not be entirely hidden by content the author created. The W3C's explanation names sticky headers as one of the typical causes. One line of CSS keeps you on the right side of it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you already use flexbox and grid comfortably, you'll notice the header is a flex row and not a grid. That's deliberate: it's one line of items whose widths come from their content. If you're unsure when to pick which, the flexbox versus grid article linked at the end walks through exactly that decision.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 3: the header that hides on the way down and comes back on the way up
&lt;/h2&gt;

&lt;p&gt;Why would you want the header to disappear at all? Good question. On a laptop, a 56 pixel header is a thin strip. On a phone held in landscape, the same header can take a big share of the screen, and while someone is reading down the page, they don't need your navigation. The moment they scroll up, even a little, they're probably looking for something, so the header comes back.&lt;/p&gt;

&lt;p&gt;Before the code, the idea. The browser tells us how far the page is scrolled, as a number. We remember the last number. When a new one arrives, we compare: bigger means the reader is going down, smaller means up. Down, hide the header. Up, show it. That's the whole idea. Everything else in the script is about doing it politely.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;header.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"[data-header]"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;THRESHOLD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;lastY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scrollY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;ticking&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scrollY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;delta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;lastY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delta&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;THRESHOLD&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;goingDown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;delta&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pastHeader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;offsetHeight&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;focusInside&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;activeElement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"is-hidden"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;goingDown&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;pastHeader&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;focusInside&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;lastY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;ticking&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"scroll"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;ticking&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ticking&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;requestAnimationFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;passive&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"focusin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"is-hidden"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Line by line:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;const header finds the header through its data-header hook.&lt;/li&gt;
&lt;li&gt;THRESHOLD = 8 means we ignore movements smaller than 8 pixels. Without it, a shaky thumb on a phone would make the header flicker in and out. The number is a feel thing. Try 4 and 16 and pick what feels calm.&lt;/li&gt;
&lt;li&gt;lastY remembers where the page was the last time we made a decision. window.scrollY is how many pixels the page is scrolled from the top.&lt;/li&gt;
&lt;li&gt;ticking is a flag that says "an update is already planned". You'll see why in a moment.&lt;/li&gt;
&lt;li&gt;Inside update(), Math.max(window.scrollY, 0) protects us from negative numbers. On some phones, pulling the page down past the top bounces it, and the scroll position can be reported as below zero for a moment.&lt;/li&gt;
&lt;li&gt;delta is the difference between now and the last decision. If it's smaller than the threshold, we do nothing and keep lastY where it was, so small movements add up until they count.&lt;/li&gt;
&lt;li&gt;goingDown is true when delta is positive.&lt;/li&gt;
&lt;li&gt;pastHeader makes sure we never hide the header while the reader is still near the top of the page, where hiding it would just leave an empty strip.&lt;/li&gt;
&lt;li&gt;focusInside checks whether the keyboard focus is on one of the header's links. If it is, we never hide the header, because a keyboard user must be able to see where they are.&lt;/li&gt;
&lt;li&gt;classList.toggle("is-hidden", condition) adds the class when the condition is true and removes it when it's false. One line handles both directions.&lt;/li&gt;
&lt;li&gt;Then we store the new position in lastY and set ticking back to false.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the bottom half. The scroll event can fire many times while the page moves. If we did all our work in every single event, we'd be doing it more often than the screen can even show. So the listener only does one thing: if no update is planned yet, it plans one with requestAnimationFrame, which runs our function right before the browser draws the next frame. Ten scroll events between two frames lead to one update. That's what the ticking flag is for.&lt;/p&gt;

&lt;p&gt;The { passive: true } option is a promise to the browser that this listener will never cancel the scroll. The browser can then scroll right away instead of waiting to see what our code wants. We never cancel scrolling here, so it's free speed.&lt;/p&gt;

&lt;p&gt;The last listener shows the header again as soon as anything inside it receives focus. Picture someone who scrolled down with the arrow keys and then presses Shift and Tab to go back to the menu. Without this line, they'd be focused on a link that is hidden above the screen.&lt;/p&gt;

&lt;p&gt;The script only adds and removes a class. The movement itself lives in CSS:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;styles.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.site-header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;transform&lt;/span&gt; &lt;span class="mi"&gt;200ms&lt;/span&gt; &lt;span class="n"&gt;ease-out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.site-header.is-hidden&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;-100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;transform: translateY(-100%) moves the header up by 100% of its own height. That's why we don't need to know the height in JavaScript. Whether it's 56 or 69 pixels, -100% is exactly enough to move it out of sight.&lt;/li&gt;
&lt;li&gt;transition: transform 200ms ease-out turns the jump into a short slide. ease-out starts fast and slows down at the end, which feels natural for something leaving the screen.&lt;/li&gt;
&lt;li&gt;In the real stylesheet the transition line sits in the same .site-header rule as the sticky lines from step 2. I split it out here so you can see it on its own.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why move it with transform and not by changing top or height? Because changing height or top makes the browser recalculate where everything else on the page sits, on every frame of the animation. A transform moves the header's already painted picture without touching anything else. The &lt;a href="https://web.dev/articles/animations-guide" rel="noopener noreferrer"&gt;web.dev guide to high-performance animations&lt;/a&gt; gives the same advice in plain words: stick to transform and opacity.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Notice what happens if the script fails to load, or throws an error before it runs. Nothing breaks. The header just stays sticky and visible, because the class that hides it can only ever come from the script. That's called progressive enhancement: the page works without the extra, and the extra makes it nicer. Build every small effect this way.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 4: respect people who asked for less motion
&lt;/h2&gt;

&lt;p&gt;Some people get dizzy or sick from movement on screens. Every major operating system has a setting for this, often called "Reduce motion", and the browser passes it to your CSS as the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion" rel="noopener noreferrer"&gt;prefers-reduced-motion media feature&lt;/a&gt;. MDN explains that animations such as scaling or panning large objects can be vestibular motion triggers, which means they can upset the sense of balance. A header that slides across the whole width of the screen fits that description.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;styles.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;prefers-reduced-motion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.site-header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@media&lt;/code&gt; (prefers-reduced-motion: reduce) applies the rules inside only when the reader has turned on the reduced motion setting.&lt;/li&gt;
&lt;li&gt;transition: none removes the slide. The header still hides and comes back, but it does so instantly, with no movement in between.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Is that enough, or should the header stop hiding completely for these readers? Honestly, it depends on your page. An instant change is not motion, so I'm comfortable keeping the hiding. If your header is very tall, or your readers are likely to be sensitive to movement, the stricter choice is to skip the hiding entirely: read the same setting in JavaScript with window.matchMedia("(prefers-reduced-motion: reduce)").matches and don't attach the scroll listener.&lt;/p&gt;

&lt;p&gt;For the record, the WCAG rule about this, &lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/animation-from-interactions.html" rel="noopener noreferrer"&gt;Animation from Interactions&lt;/a&gt;, is level AAA, the strictest level, above the AA level most projects aim for. I'd still do it. It costs four lines, and the people it helps feel the difference immediately. The same goes for scroll-behavior: smooth, if you use it: put it inside a prefers-reduced-motion: no-preference block so smooth scrolling only happens for people who didn't ask for less motion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: a hero that holds on a phone
&lt;/h2&gt;

&lt;p&gt;Now the first screen under the header. The classic beginner hero is height: 100vh. The vh unit means one percent of the viewport height, so 100vh sounds like "exactly the screen". On a laptop, it is. On a phone, it often isn't, and the reason is the browser's address bar.&lt;/p&gt;

&lt;p&gt;Mobile browsers show and hide their address bar and toolbars as you scroll. So which height is "the screen", with the bars or without them? CSS answers with three units, and the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length" rel="noopener noreferrer"&gt;MDN reference for length units&lt;/a&gt; spells them out: svh is based on the small viewport, with the browser's bars showing, lvh on the large one, with them hidden, and dvh changes as the bars come and go. And here's the catch: "vh is equivalent to lvh". So 100vh is the height with the bars hidden. When the page first loads and the bars are showing, the bottom of your 100vh hero is hidden behind them. Usually that's exactly where the button is.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;styles.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.hero&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;place-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100vh&lt;/span&gt; &lt;span class="n"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--header-h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100svh&lt;/span&gt; &lt;span class="n"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;--header-h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2rem&lt;/span&gt; &lt;span class="mf"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hero&lt;/span&gt; &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mf"&gt;0.75rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.25rem&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4vw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.75rem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;18ch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hero&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;45ch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;display: grid with place-items: center puts the hero's content in the middle, both ways, with two lines.&lt;/li&gt;
&lt;li&gt;There are two min-height lines on purpose. A browser that doesn't understand svh ignores the second line and keeps the first. A browser that does understand it uses the second, because the later rule wins. This is the oldest fallback trick in CSS, and it still works.&lt;/li&gt;
&lt;li&gt;100svh minus the header's height means the header and the hero together fill the small viewport, so the button is visible on the first screen even with the address bar showing.&lt;/li&gt;
&lt;li&gt;min-height and not height, again. If the text is longer than you planned, or the reader zooms in, the hero grows instead of letting the text spill out of it.&lt;/li&gt;
&lt;li&gt;padding keeps the text off the screen edges on a phone.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The font size line is the one people copy without understanding, so let's take it apart. clamp() takes three values: a minimum, a preferred value and a maximum. The browser uses the preferred value, but never goes below the minimum or above the maximum.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2rem is the floor: 32 pixels at the default font size. The headline never gets smaller than that, even on the narrowest phone.&lt;/li&gt;
&lt;li&gt;1.25rem + 4vw is the preferred size: a fixed 20 pixels plus 4% of the screen width. In the test runs it came out at 50.4 pixels on a 760 pixel wide screen, 35 pixels at 375 and 32.8 at 320.&lt;/li&gt;
&lt;li&gt;3.75rem is the ceiling: 60 pixels. With this formula the headline reaches it at a screen width of 1,000 pixels and stops growing there, so it doesn't turn into a billboard on a big monitor.&lt;/li&gt;
&lt;li&gt;line-height: 1.1 tightens the lines. Big headlines with normal line spacing look like they're falling apart.&lt;/li&gt;
&lt;li&gt;max-width: 18ch limits the headline to roughly 18 characters per line. ch is the width of the zero character in the current font. Short lines make a big headline easier to read. The paragraph gets 45ch for the same reason.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why the 1.25rem in the middle, and not just 6vw? Because of zoom. Text sized only in vw is tied to the window width, and zooming doesn't change how wide the window is in real terms, so the headline wouldn't grow when a reader zooms in. The rem part follows the reader's settings. WCAG's &lt;a href="https://www.w3.org/WAI/WCAG22/Understanding/resize-text.html" rel="noopener noreferrer"&gt;Resize Text&lt;/a&gt; rule asks that text can be resized up to 200 percent without losing content or function. Mixing rem into the formula keeps you on the safe side.&lt;/p&gt;

&lt;h3&gt;
  
  
  The trade-off nobody tells you about
&lt;/h3&gt;

&lt;p&gt;Remember that the header is 56 pixels on a laptop and 69 on a phone, because the links wrap under the logo? Our hero subtracts --header-h, which is 56 pixels. So on that phone, the header and hero together are 13 pixels taller than the screen, and the very bottom of the hero sits just below the fold.&lt;/p&gt;

&lt;p&gt;Is that a problem? Here, no. The hero's content is centred, so those 13 pixels are empty background, and nothing is cut off. But you should know it's there. If it ever matters, you have two honest options. You can design the phone header so the links never wrap, for example by moving them behind a menu button. Or you can measure the real header height in JavaScript with a ResizeObserver and write it into --header-h. The second one is more code to maintain for 13 pixels of background, so I wouldn't start there.&lt;/p&gt;

&lt;h3&gt;
  
  
  If your hero has an image
&lt;/h3&gt;

&lt;p&gt;Our demo uses a gradient so it doesn't need any files. Most real heroes have a photo, and the photo is usually the biggest thing on the first screen. That makes it the element Google's loading metric, Largest Contentful Paint, is most likely to measure. So it's worth three attributes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt;
  &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hero-image"&lt;/span&gt;
  &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/images/bread-on-rack.jpg"&lt;/span&gt;
  &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Loaves of sourdough cooling on a wooden rack"&lt;/span&gt;
  &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"1600"&lt;/span&gt;
  &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"900"&lt;/span&gt;
  &lt;span class="na"&gt;fetchpriority&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"high"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;alt describes the photo for people who can't see it. Describe what's in it, not "hero image".&lt;/li&gt;
&lt;li&gt;width and height are the image's real size in pixels. The browser uses them to reserve the right amount of space before the file arrives, so the text doesn't jump down when the photo appears. Your CSS can still make it responsive with width: 100% and height: auto.&lt;/li&gt;
&lt;li&gt;fetchpriority="high" tells the browser this image matters more than the others, so it starts downloading it earlier.&lt;/li&gt;
&lt;li&gt;And notice what's missing: loading="lazy". Lazy loading is great for images further down the page, and harmful for the one at the top.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both of those last points have measurements behind them. The web.dev team measured that lazy loading images inside the first screen made Largest Contentful Paint worse, in their article on &lt;a href="https://web.dev/articles/lcp-lazy-loading" rel="noopener noreferrer"&gt;the performance effects of too much lazy loading&lt;/a&gt;, and their &lt;a href="https://web.dev/articles/fetch-priority" rel="noopener noreferrer"&gt;Fetch Priority guide&lt;/a&gt; shows fetchpriority="high" on the main image as the standard move.&lt;/p&gt;

&lt;h2&gt;
  
  
  All of it together
&lt;/h2&gt;

&lt;p&gt;Here's the finished page: the header from steps 1 and 2, the hiding script from step 3, the reduced motion rule from step 4 and the hero from step 5. Scroll down slowly inside the demo and watch the header slide away. Scroll up a little and it comes back. Click Menu, Visit or Order and see where the headings land. Then click inside the demo and press Tab a few times.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; Sticky header that hides on scroll, with a hero. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/sticky-header-hero-from-scratch?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=sticky-header-hero-from-scratch"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Two things in the full source you haven't seen yet. The skip link is positioned above the screen with top: -3rem and comes down to top: 0.5rem when it receives focus, so keyboard users see it and everyone else doesn't. And the checkbox called "Pretend I asked for reduced motion" exists only in this demo. It adds a class to the body that removes the transition, so you can feel the difference without changing your system settings. In a real project, the media query from step 4 does that job.&lt;/p&gt;

&lt;p&gt;Try one more thing: click Visit while you're at the top. The page jumps down, so the script reads it as scrolling down and hides the header. The heading lands with a little extra space above it, because scroll-padding reserved room for a header that has just left. Jump back up with the logo and the header returns. I left that behaviour in on purpose. It's correct, and it's the kind of detail you should notice when you test your own pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  So that's all it is
&lt;/h2&gt;

&lt;p&gt;Look at what we actually wrote. The sticky header is two lines, position: sticky and top: 0, plus the knowledge that it can only move inside its parent and that an overflow value on any ancestor can steal it. The hiding header is a comparison of two numbers and a class. The slide is one transform. Reduced motion is four lines. The hero is min-height with svh and a font size with clamp().&lt;/p&gt;

&lt;p&gt;No library, no framework, nothing to install. When you see a polished header on a big website, it's very likely this, plus good design. The tricks are small. Knowing which small trick solves which problem is the actual skill.&lt;/p&gt;

&lt;h2&gt;
  
  
  What breaks in real projects, and the Plan B
&lt;/h2&gt;

&lt;p&gt;A good programmer thinks a few steps ahead. Here's what tends to go wrong once a header like this meets a real site and real people.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Something else is sticky too. A cookie banner at the bottom, a promotion bar above the header, a sticky table of contents. Each one eats screen space and each one can cover a focused link. Count your sticky things on a phone in landscape before you ship.&lt;/li&gt;
&lt;li&gt;A wrapper you didn't write. Frameworks and page builders love to wrap your page in divs, and some of those divs carry overflow: hidden. Run the DevTools snippet from earlier before you rewrite your header.&lt;/li&gt;
&lt;li&gt;A huge header. If your header holds a search field, a promotion line and two rows of links, sliding it away on scroll is less of a nice touch and more of a necessity. Sometimes the better fix is a smaller header.&lt;/li&gt;
&lt;li&gt;The header hides while someone is using it. Our script never hides it while focus is inside, but if your header has a dropdown menu, also keep it visible while the dropdown is open.&lt;/li&gt;
&lt;li&gt;Very short screens. A phone in landscape can be under 400 pixels tall. Even a modest sticky header is a big slice of that.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For that last case, here's a small Plan B that turns the sticky behaviour off when the screen is very short:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;styles.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;max-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30rem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.site-header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;static&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;max-height: 30rem matches screens up to 480 pixels tall at the default font size, which covers most phones held sideways.&lt;/li&gt;
&lt;li&gt;position: static is the default positioning, so the header scrolls away with the page like any normal element and gives the whole screen back to the content.&lt;/li&gt;
&lt;li&gt;Our script can keep running. It still adds the class, but a header that has already scrolled out of view doesn't care.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the test for this article, the header scrolled away with the page in a window 400 pixels tall and stayed sticky in one 600 pixels tall. And if your plan B for all of this is "hope nobody uses a phone sideways", that's not a plan B.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Don't copy a hide-on-scroll script that listens to the scroll event and changes top or height directly on every event. It works on a fast laptop and stutters on a cheap phone, which is where most of your readers are. Plan the update with requestAnimationFrame, move the header with transform, and mark the listener as passive.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  For advanced readers: a shadow only when the header is stuck
&lt;/h2&gt;

&lt;p&gt;A nice finishing touch is a soft shadow under the header, but only once it's actually stuck. At the very top of the page the header sits on the hero and a shadow would look odd. CSS alone has long had no way to ask "is this sticky element stuck right now", so the usual trick is a sentinel: an invisible one-pixel element placed right above the header. When the sentinel scrolls out of view, the header must be stuck.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"header-sentinel"&lt;/span&gt; &lt;span class="na"&gt;aria-hidden&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;header&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"site-header"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Harbor Lane Bakery&lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;stuck-shadow.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sentinel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".header-sentinel"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;stickyHeader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".site-header"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;stickyHeader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"is-stuck"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isIntersecting&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sentinel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The sentinel is an empty div, one pixel tall in CSS, with aria-hidden="true" so screen readers skip it. It sits directly before the header.&lt;/li&gt;
&lt;li&gt;IntersectionObserver is a browser feature that tells you when an element enters or leaves the visible area. You don't listen to scroll events at all; the browser does the watching for you.&lt;/li&gt;
&lt;li&gt;The callback receives a list of entries. We watch only one element, so we take the first one with [entry].&lt;/li&gt;
&lt;li&gt;entry.isIntersecting is true while the sentinel is visible. When it's not visible, the page has scrolled past it, the header is stuck, and we add the is-stuck class. A rule like .site-header.is-stuck { box-shadow: 0 2px 8px rgb(0 0 0 / 0.12); } draws the shadow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the test, the class was off at the top, on after scrolling 300 pixels, and off again after scrolling back. The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API" rel="noopener noreferrer"&gt;Intersection Observer API reference&lt;/a&gt; is worth reading in full if you haven't used it. It's the same tool behind lazy loading, infinite lists and "mark as read" features.&lt;/p&gt;

&lt;p&gt;There is also a newer, CSS-only way. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_conditional_rules/Container_scroll-state_queries" rel="noopener noreferrer"&gt;Container scroll-state queries&lt;/a&gt; let you style an element based on whether a sticky container is stuck, with no JavaScript at all. Newer CSS features often arrive in one browser first, so check the compatibility table on that page before you rely on it, and keep the sentinel as the fallback.&lt;/p&gt;

&lt;p&gt;One last note on performance for the hiding script. We read window.scrollY and header.offsetHeight inside a requestAnimationFrame callback, and we write only a class. Reading layout values and then writing styles in the same frame, again and again, is what makes scroll effects stutter. Read first, write once, and the browser has an easy job.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to learn next
&lt;/h2&gt;

&lt;p&gt;If the flex row in the header made you wonder when to use flexbox and when grid, &lt;a href="https://codefromscratch.org/blog/css-flexbox-vs-grid-real-layouts?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=sticky-header-hero-from-scratch"&gt;Flexbox vs Grid: How to Choose, on Real Layouts&lt;/a&gt; answers exactly that on real page pieces. The next section on most landing pages is a pricing table, and &lt;a href="https://codefromscratch.org/blog/pricing-table-from-scratch-css?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=sticky-header-hero-from-scratch"&gt;Build a Pricing Table From Scratch&lt;/a&gt; rebuilds that one the same way we rebuilt the header today.&lt;/p&gt;

&lt;p&gt;Our three navigation links were written by hand. On a real site they often come from a list of data, and &lt;a href="https://codefromscratch.org/blog/render-lists-without-repeating-code?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=sticky-header-hero-from-scratch"&gt;One Card, Many Posts: Render Lists Without Repeating Code&lt;/a&gt; shows how to write one template and let the data fill it. And if you're right at the start and some of today's words were new, &lt;a href="https://codefromscratch.org/blog/what-is-web-development-beginners-guide?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=sticky-header-hero-from-scratch"&gt;What Is Web Development? A Complete Beginner's Guide&lt;/a&gt; puts HTML, CSS and JavaScript into one picture.&lt;/p&gt;

&lt;p&gt;Then practise. Pick a website you use every day, look at its header and its first screen, and rebuild the pattern with your own text and colours. Test it at 320 pixels wide, with the keyboard only, and with reduced motion switched on. When all three feel right, you've learned more than any list of CSS properties could teach you.&lt;/p&gt;

&lt;p&gt;You can do this, and you have to. If you weren't capable, I wouldn't spend my time on you. Just don't give up, and you'll always have me on your side.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/sticky-header-hero-from-scratch?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=sticky-header-hero-from-scratch"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=sticky-header-hero-from-scratch"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>html</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Production-Grade Code: What Separates Hobby Apps from Real Ones</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Sun, 15 Nov 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/codefromscratch/production-grade-code-what-separates-hobby-apps-from-real-ones-eof</link>
      <guid>https://dev.to/codefromscratch/production-grade-code-what-separates-hobby-apps-from-real-ones-eof</guid>
      <description>&lt;p&gt;Your app works on your laptop. Now picture a thousand strangers signing up tomorrow: one types garbage into every field, one forgets a password, a bot tries ten thousand logins, and your database goes down at 3 a.m. Would you sleep? Today I'll give you the eight habits that make the answer yes, with the code for each one and exactly what's enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  The question I never asked
&lt;/h2&gt;

&lt;p&gt;When I started building things, I built them from my head. No plan, no sketch. I kept going until I liked how it looked. Semantics, SEO, code security, the safety of the people using it: none of that crossed my mind.&lt;/p&gt;

&lt;p&gt;And there's one question I never once asked: what happens with 1,000 users who have profiles? How do I protect their accounts from hackers? How do they reset a password? What do I do when my own bug hurts them? I had no answers, because I had never thought about it. Nothing had forced me to. On my laptop, there was exactly one user, and he was very polite.&lt;/p&gt;

&lt;p&gt;That's the gap this article is about. People call it hobby code versus production code, and it sounds like a difference in talent. It isn't. It's a list, and you can learn a list.&lt;/p&gt;

&lt;p&gt;Some words first, in case they're new. Production is the version of your app that real people use, as opposed to the copy on your own computer. Production-grade means the app behaves on purpose when things go wrong, not only when they go right. A deploy is the moment you put a new version into production.&lt;/p&gt;

&lt;p&gt;Think of cooking dinner for your family versus opening a restaurant. The recipe can be the same. But the restaurant has to deal with the supplier who doesn't show up, the customer who walks out without paying, and the fridge that dies overnight. Nobody tastes any of that on the plate. It's still most of the job.&lt;/p&gt;

&lt;p&gt;Here's how to read this. If you're a beginner, go top to bottom, and don't panic. You don't need all eight today, and I'll tell you when something is overkill. If you've shipped a few things, go straight to the numbered sections and check the code against your own. If you make architecture calls, look for the parts marked "For advanced readers" and the failure modes in each section.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why tutorials never told you any of this
&lt;/h2&gt;

&lt;p&gt;Every tutorial ends the same way. The form submits, the data shows up, and the video stops. That's the happy path: the one route through your code where everyone behaves and everything is up. It's easy to teach because it's short.&lt;/p&gt;

&lt;p&gt;I finished courses like that and still felt &lt;a href="https://codefromscratch.org/blog/why-courses-leave-you-feeling-like-you-know-nothing?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;like I knew nothing&lt;/a&gt;. The courses weren't lying. They just stopped exactly where the real work starts. What if the input is malformed? What if the database is asleep? The tutorial doesn't say, because on your laptop, with one friendly user, it never happens.&lt;/p&gt;

&lt;p&gt;AI tools make this gap wider, and I say that as someone who uses them every day. You can now get to a working happy path in an afternoon. But AI can't know what's in your head, and it can hallucinate or assume things it shouldn't, so I check what it writes as far as I can. The people who &lt;a href="https://codefromscratch.org/blog/what-is-vibe-coding?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;think they can skip understanding&lt;/a&gt; are the ones who get stuck, because when it breaks, they can't tell what broke. This list is how you judge the code, no matter who or what typed it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea before the code: eight questions
&lt;/h2&gt;

&lt;p&gt;A good programmer thinks a few steps ahead: scaling, security, reliability, and always a Plan B. That sounds big, so let's make it small. Production-grade comes down to eight questions you ask about every feature:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Who sent this data, and what if they lied?&lt;/li&gt;
&lt;li&gt;When this fails, what does the user see, and do I find out?&lt;/li&gt;
&lt;li&gt;What happens when someone calls this ten thousand times?&lt;/li&gt;
&lt;li&gt;A user reports a problem from yesterday. Can I find out what happened?&lt;/li&gt;
&lt;li&gt;If I break this next month, what will tell me?&lt;/li&gt;
&lt;li&gt;If a stranger reads my code or calls my endpoints, what can they get?&lt;/li&gt;
&lt;li&gt;Can I change the database without losing anyone's data?&lt;/li&gt;
&lt;li&gt;When a service I depend on goes down, how much of my app goes with it?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each question below gets the same treatment: why it exists, the failure it prevents, the code, and where "good enough" sits. I care about that last one. Over-engineering is a real mistake too, and if you're building a personal page with no logins and no money, most of this is more than you need.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Checked on October 30, 2026 with Next.js 16.4, React 19, Zod 4.3, Stripe SDK 20.4, Vitest 3 and PostgreSQL (through PGlite). All TypeScript passed strict type-checking, and the test suite, the validation rules, the request ID code and the SQL were actually run. The Upstash limiter was type-checked against version 2.2 only, because it needs a real Redis to run. The Prisma and Next.js docs change quickly, so check the linked pages if you're reading this much later.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  1. Every input is a lie until you've checked it
&lt;/h2&gt;

&lt;p&gt;TypeScript gives you a comfortable feeling. You say quantity is a number, the compiler nods, everything looks safe. But types are erased before your code runs. At runtime, your server receives whatever bytes the network delivers, and the network hasn't read your interfaces.&lt;/p&gt;

&lt;p&gt;A trust boundary is any point where data enters your code from outside it: forms, URL parameters, request bodies, webhooks, replies from other companies' APIs. Picture a bouncer at a club door. Once you're inside, nobody asks for your ID again, so the door is where the check has to happen. The rule is simple: outside data is hostile until a schema proves otherwise. A schema is just a written description of what valid data looks like.&lt;/p&gt;

&lt;p&gt;Here's the classic failure. A beginner's checkout sends the price along with the order, because that's where the tutorial put it. Anyone can open the browser's developer tools and change that number. Stripe won't save you, because when you create a one-off price, &lt;a href="https://docs.stripe.com/api/checkout/sessions/create" rel="noopener noreferrer"&gt;the amount is what you tell it&lt;/a&gt;. Try it yourself below. Change the price, then send it to each server.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; Who decides the price?. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/production-grade-code-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Both servers got the same request. The only difference is that one believed it. Here's the real version with Zod, the validation library most TypeScript projects use.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app/checkout/actions.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="s1"&gt;'use server'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zod'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/lib/db'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;startCheckout&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/lib/stripe'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;checkoutInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cuid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createCheckout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;checkoutInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;safeParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Invalid input.'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findUnique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;productId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Product not found.'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;startCheckout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;priceCents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;'use server' turns this function into a Server Action, which you can call from a form or button. Next.js is blunt about what that means: treat it as reachable by a direct POST request. It's a public door, even if no button on your site points at it.&lt;/li&gt;
&lt;li&gt;checkoutInput is the schema. z.cuid() accepts only IDs in the format Prisma generates with cuid(), so change this if your IDs look different. z.int().min(1).max(10) rejects 0, 2.5, and someone ordering a million. These top-level forms are current in Zod 4; the older z.string().email() style is deprecated.&lt;/li&gt;
&lt;li&gt;raw: unknown is on purpose. Typing it as a nice interface would be a lie, because you don't know yet. unknown forces you to check before you touch it.&lt;/li&gt;
&lt;li&gt;safeParse returns a result instead of throwing, so bad input is a normal outcome and not a crash. Remove this check and quantity: -5 goes straight to your payment code.&lt;/li&gt;
&lt;li&gt;The price comes from db.product, your own database. If the input carries an extra priceCents: 1, Zod drops it from the output, so a forged price never even reaches the next line.&lt;/li&gt;
&lt;li&gt;Failures come back as plain return values. Next.js recommends exactly that for expected errors in Server Actions, so the form can show the message.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From the docs: &lt;a href="https://nextjs.org/docs/app/guides/data-security" rel="noopener noreferrer"&gt;reachable by a direct POST request&lt;/a&gt;, &lt;a href="https://zod.dev/v4/changelog" rel="noopener noreferrer"&gt;Zod 4&lt;/a&gt;, &lt;a href="https://nextjs.org/docs/app/getting-started/error-handling" rel="noopener noreferrer"&gt;Next.js recommends exactly that&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Webhooks deserve a special mention. A webhook is another service calling your server to tell you something happened, like "this payment succeeded". Anyone on the internet can send that same request to that same URL, so you verify the signature before believing a word of it. &lt;a href="https://codefromscratch.org/blog/stripe-webhook-verification?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;The Stripe webhook guide&lt;/a&gt; shows how, and &lt;a href="https://codefromscratch.org/blog/zod-at-trust-boundaries?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;the Zod guide&lt;/a&gt; goes deeper on schemas. If you've never compared browser checks and server checks side by side, &lt;a href="https://codefromscratch.org/blog/login-form-validation-client-and-server?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;the login form article&lt;/a&gt; has a live demo of both.&lt;/p&gt;

&lt;p&gt;Good enough: a schema on every Server Action and route handler that accepts input, and one hard rule that prices, roles and other users' IDs never come from the client. Inside your own code, between your own functions, you don't need to re-validate. Check at the door.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Errors are part of the design
&lt;/h2&gt;

&lt;p&gt;In production, errors aren't exceptional. They're weather. Databases pause, APIs time out, someone submits a form on a train going into a tunnel. How your app behaves in those moments is either something you decided or something that happens to you.&lt;/p&gt;

&lt;p&gt;The worst version is silence, and it usually comes from an empty catch block: code that grabs an error and does nothing with it. Turn off the network in this demo and submit both forms.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; The form that lies. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/production-grade-code-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Look at what the first form did. The request failed, and it thanked the user anyway. The user waits for emails that never come. You look at your subscriber count and decide your content isn't good enough. One empty catch lied to both of you. OWASP, the group that publishes the best-known list of web security risks, added &lt;a href="https://top10.owasp.org/2025/A10_2025-Mishandling_of_Exceptional_Conditions/" rel="noopener noreferrer"&gt;Mishandling of Exceptional Conditions&lt;/a&gt; as a new category in its 2025 edition, so this isn't only about manners.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Every catch block must do one of three things: rethrow the error, log it and fall back on purpose, or show the user an honest message. A catch that does none of these isn't handling the error. It's hiding it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For rendering failures, Next.js gives you error.tsx. Put one in a folder and it catches errors from that part of the page tree, so a broken dashboard doesn't take your whole site down.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app/dashboard/error.tsx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="s1"&gt;'use client'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;DashboardError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;retry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;digest&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;retry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"alert"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;We&lt;/span&gt; &lt;span class="n"&gt;couldn&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;apos&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="n"&gt;load&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Your&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="n"&gt;safe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nc"&gt;Please&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="n"&gt;again&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;digest&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Reference&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;support&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;button&lt;/span&gt; &lt;span class="n"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;retry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Try&lt;/span&gt; &lt;span class="n"&gt;again&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;'use client' is required, because error boundaries must be Client Components. A boundary has to keep working in the browser after something went wrong on the server.&lt;/li&gt;
&lt;li&gt;error.digest is a generated hash of the error. In production, errors from Server Components reach the browser with a generic message, so you don't leak internals. The digest lets you match this screen to the real error in your server logs.&lt;/li&gt;
&lt;li&gt;{error.digest &amp;amp;&amp;amp; ...} is there because errors thrown in the browser don't get that server hash. Without the check you'd show "Reference for support:" followed by nothing.&lt;/li&gt;
&lt;li&gt;retry re-renders the failed part of the page. It became stable in Next.js 16.3, so older tutorials will show reset, and on those older versions that's what you use. If your types complain about retry, check your Next.js version first.&lt;/li&gt;
&lt;li&gt;Look at what the message tells the person: what failed, that their data is safe, what to do next. Compare that with "Oops, something went wrong".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From the docs: &lt;a href="https://nextjs.org/docs/app/api-reference/file-conventions/error" rel="noopener noreferrer"&gt;error boundaries must be Client Components&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For advanced readers: error.tsx has blind spots. It doesn't wrap the layout in its own folder, so root layout errors need global-error.tsx. It doesn't catch errors in event handlers either; those you catch yourself and keep in state. And expected Server Action failures should be return values, not throws. If you're wondering where to put boundaries, the error boundaries guide linked below covers it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Good enough: an error.tsx on every major section, zero empty catch blocks, and honest messages. The full reasoning on placement is in &lt;a href="https://codefromscratch.org/blog/error-boundaries-done-right?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;the error boundaries guide&lt;/a&gt;. You don't need a fancy error library. You need to stop lying when things break.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The day you get traffic is the day you get abuse
&lt;/h2&gt;

&lt;p&gt;Once your app has a public URL, not all of your visitors are people. Scrapers copy your content. Scanners probe for known holes. Bots replay leaked password lists against anything shaped like a login form. None of it is personal. It's just cheap to do.&lt;/p&gt;

&lt;p&gt;Picture a contact form that sends email. A bot finds it and submits it all night. Your sending quota is gone, and your real mail starts looking like spam. A login with no limit is even worse: it's a free password-testing service that you host for attackers. And if your hosting bills per use, an endpoint anyone can call in a loop is a bill with your card on file.&lt;/p&gt;

&lt;p&gt;Rate limiting is the fix: you count requests per person and refuse the extras. It's the same as a ticket machine at the door that stops at a set number per person. The status code for refusing is 429, Too Many Requests. Click slowly in this demo, then press the bot button. The window here is 20 seconds so you don't have to sit around.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; A rate limiter you can annoy. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/production-grade-code-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One trap before the code. You might write a counter in a normal variable, and it'll even pass your tests. In production, your app may run on many instances at once, and each one has its own memory, so each one has its own count. The counter has to live somewhere they all share. Redis, a very fast database for small pieces of data, is the usual choice, and Upstash offers it over plain HTTP, which suits serverless.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lib/rate-limit.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Ratelimit&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@upstash/ratelimit'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Redis&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@upstash/redis'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;loginLimiter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Ratelimit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromEnv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;limiter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Ratelimit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slidingWindow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'1 m'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'rl:login'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Redis.fromEnv() reads your connection details from environment variables, so no secrets sit in the code.&lt;/li&gt;
&lt;li&gt;slidingWindow(5, '1 m') means five requests per rolling minute. A fixed window resets on the clock, which lets someone send five at 12:00:59 and five more at 12:01:00. Sliding smooths that out. Upstash notes that it's an approximation and costs more to run than a fixed window, a trade I'd accept on a login.&lt;/li&gt;
&lt;li&gt;prefix keeps these counters apart from any other limiter you add later, like one for your contact form.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From the docs: &lt;a href="https://upstash.com/docs/redis/sdks/ratelimit-ts/algorithms" rel="noopener noreferrer"&gt;Upstash's algorithm docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app/api/login/route.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ipAddress&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@vercel/functions'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;handleLogin&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/lib/login'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;loginLimiter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/lib/rate-limit'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;POST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ipAddress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;'unknown'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reset&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;loginLimiter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reset&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Too many attempts. Please wait a moment.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;'Retry-After'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;handleLogin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;ipAddress(request) comes from &lt;code&gt;@vercel/functions&lt;/code&gt;. On other hosts, read the IP the way your host documents, because headers a client can set are headers a client can fake.&lt;/li&gt;
&lt;li&gt;?? 'unknown' handles the case with no IP, like local development. Everyone without an IP shares one bucket, which is fine locally.&lt;/li&gt;
&lt;li&gt;reset is a timestamp in milliseconds, while Retry-After is in seconds. Skip the conversion and a one-minute wait turns into more than 16 hours, so the math on that line matters. Math.max keeps it at one second or more.&lt;/li&gt;
&lt;li&gt;handleLogin only runs after the check. The limit has to sit in front of the expensive work, or you've already paid for the request you're refusing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From the docs: &lt;a href="https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package" rel="noopener noreferrer"&gt;&lt;code&gt;@vercel/functions&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://upstash.com/docs/redis/sdks/ratelimit-ts/methods" rel="noopener noreferrer"&gt;timestamp in milliseconds&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Retry-After" rel="noopener noreferrer"&gt;Retry-After is in seconds&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For advanced readers: three failure modes. First, by default a limiter timeout lets the request through after 5 seconds, so if Redis is down, your limit is gone. That's a sensible choice for a blog comment and a debatable one for login, so decide it. Second, an IP limit doesn't stop credential stuffing from thousands of IPs, so add a second limiter keyed by the account being attacked, and be careful not to let an attacker lock real users out. Third, whole offices and schools can share one IP, so keep limits generous on normal pages.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Plan B if you don't want another service: Vercel has &lt;a href="https://vercel.com/docs/vercel-firewall/vercel-waf/rate-limiting" rel="noopener noreferrer"&gt;firewall rate limiting on all plans&lt;/a&gt;, with one rule and fixed windows on the free plan. That can cover your login route while you're small. More options, including what to count when IPs are shared, are in &lt;a href="https://codefromscratch.org/blog/api-rate-limiting-nextjs?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;the rate limiting guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Good enough: strict limits on login, on anything that sends email, and on anything that costs you money per call. Everything else gets a generous default or nothing at all, so real people never notice it.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Logs you can actually search at 2 a.m.
&lt;/h2&gt;

&lt;p&gt;In development, you are the monitoring. The console is open, the error shows up in red, you fix it. In production you're asleep, and your app volunteers nothing. Whatever you didn't deliberately record never happened.&lt;/p&gt;

&lt;p&gt;The failure arrives by email: "I tried to buy your course yesterday. The money left my account but I never got access." No logs means no answer. You can't find the request, and you can't see which step failed. You're left apologizing and guessing, and that's the "my own bug hurts them" moment I never prepared for.&lt;/p&gt;

&lt;p&gt;Think of a parcel with a tracking number. Every depot scans the same number, so when the parcel goes missing, you can see the last place it was. A request ID is that tracking number: one random ID, stamped on every log line that request produces. Structured logging means each line is data (usually JSON) instead of a sentence, so you can search it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lib/log.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'info'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'warn'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'error'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Level is a small union type, so a typo like 'eror' fails at compile time.&lt;/li&gt;
&lt;li&gt;ctx is whatever context you have: the request ID, a product ID. It defaults to an empty object so you can skip it.&lt;/li&gt;
&lt;li&gt;...ctx comes first on purpose. Later keys win in JavaScript, so if someone passes a stray level in ctx, it can't overwrite the real level. It's easy to get this backwards.&lt;/li&gt;
&lt;li&gt;console[level] picks console.info, console.warn or console.error, and JSON.stringify makes it one searchable line. Your host collects anything written to the console.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the part that creates the tracking number. Next.js 16 &lt;a href="https://nextjs.org/docs/app/api-reference/file-conventions/proxy" rel="noopener noreferrer"&gt;renamed middleware to proxy&lt;/a&gt;, so older articles, including some of mine, still call this file middleware.ts. It's the same idea: code that runs before a request reaches your page.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;proxy.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;NextResponse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;NextRequest&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'next/server'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;proxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;NextRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;requestId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;randomUUID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Headers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'x-request-id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;requestId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;NextResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'x-request-id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;requestId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;matcher&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'/((?!_next/static|_next/image|favicon.ico).*)'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;crypto.randomUUID() makes the ID. We always create a new one, so a fake x-request-id sent by a client is gone by the time the request moves on. Otherwise an attacker could pollute your logs with IDs of their choosing.&lt;/li&gt;
&lt;li&gt;new Headers(request.headers) copies the incoming headers, because you can't simply edit them in place.&lt;/li&gt;
&lt;li&gt;NextResponse.next({ request: { headers } }) passes the new header on to your page. The nesting matters. The docs warn that NextResponse.next({ headers }) without request sends those headers to the client instead.&lt;/li&gt;
&lt;li&gt;response.headers.set puts the ID on the response too, so a support email can include it. This one is safe to expose, since it's just a random reference.&lt;/li&gt;
&lt;li&gt;matcher skips static files. Without a matcher, the proxy runs on every single request, including every image.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;lib/report.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'next/headers'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;log&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/lib/log'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reportCheckoutFailure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;requestId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'x-request-id'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'error'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'checkout failed'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;requestId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's how you read it back anywhere on the server. headers() is async in current Next.js, which is why there's an await. String(error) matters too: passing an Error object directly to JSON.stringify gives you {}, which is a very quiet way to lose the one thing you needed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Never log passwords, tokens, full card data or session cookies. Be careful with emails and other personal details too. A log is a database that everyone forgets is a database. Log the ID of the user, not their life story.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Add error tracking on top. Sentry has a free tier and will alert you when something new starts failing, and &lt;a href="https://codefromscratch.org/blog/observability-solo-saas?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;the observability guide&lt;/a&gt; shows a full solo setup. The logging details are in &lt;a href="https://codefromscratch.org/blog/structured-logging-nextjs?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;the structured logging guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Good enough: error tracking for crashes, and request IDs in logs on the paths that handle money, logins and webhooks. You don't need distributed tracing for an app with one service in it. Here's your test: a user reports a problem from yesterday. Can you find out what happened? If yes, you have enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Tests on the paths that move money, not everywhere
&lt;/h2&gt;

&lt;p&gt;A test is a small program that runs your code and checks the answer. Think of it as a signed statement: this worked on this date, and I want to hear about it the moment it stops working. That matters, because the person most likely to break your checkout is you, three months from now, cleaning something up with total confidence.&lt;/p&gt;

&lt;p&gt;Testing everything is a waste for a solo developer, and you'd spend weeks on code a glance could verify. Testing nothing is worse. So test the paths where a bug costs money, access or trust: login, payment, permissions, personal data. Here's a pricing function, and it has two ideas in it worth stealing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lib/pricing.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;CODES&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;percentOff&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="no"&gt;LAUNCH50&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;percentOff&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'2099-01-01'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;OLD20&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;percentOff&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'2024-12-01'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;applyDiscount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;discount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;CODES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;discount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Unknown code'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;discount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Expired code'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cents&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;discount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;percentOff&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Everything is in cents, as a whole number. Never keep money in decimals. In JavaScript, 0.1 + 0.2 gives 0.30000000000000004, and those tiny errors add up in exactly the place you don't want them. Stripe's API works in the smallest currency unit too.&lt;/li&gt;
&lt;li&gt;now = new Date() is a default parameter. In real use you never pass it. In a test you pass a fixed date, so the test gives the same answer forever. A test that reads the real clock passes today and fails on some random Tuesday years from now.&lt;/li&gt;
&lt;li&gt;Math.round keeps the result in whole cents. Half of 999 is 499.5, and there's no such thing as half a cent.&lt;/li&gt;
&lt;li&gt;Throwing on an unknown or expired code means a bad code can never quietly become a full-price or free purchase. The caller has to deal with it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;lib/pricing.test.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'vitest'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;applyDiscount&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'./pricing'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'applyDiscount'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'takes the percentage off once'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;applyDiscount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'LAUNCH50'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'always returns whole cents'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;applyDiscount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;999&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'LAUNCH50'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'rejects a code nobody created'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;applyDiscount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'FREESTUFF'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toThrow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Unknown code'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'rejects an expired code'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;afterExpiry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2025-01-01'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;applyDiscount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'OLD20'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;afterExpiry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toThrow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Expired code'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;describe groups related tests, and each it() is one test case. Each name says what should be true, so a failure reads like a sentence.&lt;/li&gt;
&lt;li&gt;toBe(2500) checks the exact number, including that the discount only applied once.&lt;/li&gt;
&lt;li&gt;The 999 case is the rounding edge, the kind of value that causes real bugs.&lt;/li&gt;
&lt;li&gt;The throw tests wrap the call in an arrow function, () =&amp;gt; ..., so Vitest can run it and catch the error itself. Without the wrapper, the error would blow up before expect ever saw it.&lt;/li&gt;
&lt;li&gt;afterExpiry is that fixed date in action. Run this file with Vitest and all four tests pass.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One rule makes this compound: every bug you fix gets a test that would have caught it. No bug gets to embarrass you twice. &lt;a href="https://codefromscratch.org/blog/testing-react-applications-a-complete-strategy?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;The React testing strategy&lt;/a&gt; covers which kind of test goes where.&lt;/p&gt;

&lt;p&gt;Good enough: tests that pin down pricing, permissions and checkout. That beats a mountain of snapshot tests on buttons that change every week. If a path moves money, grants access, or touches data you'd have to apologize for losing, it gets a test. The rest can wait until it breaks once.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Security is mostly boring, and that's why people skip it
&lt;/h2&gt;

&lt;p&gt;Security has a glamorous part, the clever exploits people give talks about. And it has a boring part that decides most of what actually goes wrong: where secrets live, who's allowed to do what, which settings are on. None of it is hard. It just has to be done every time.&lt;/p&gt;

&lt;h3&gt;
  
  
  The most common hole: checking who, but not whose
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://top10.owasp.org/2025/A01_2025-Broken_Access_Control/" rel="noopener noreferrer"&gt;Broken access control is number one&lt;/a&gt; on the OWASP Top 10 2025. In plain words: a logged-in user can touch something that isn't theirs, often just by changing an ID. Like a hotel where your key card opens every room because the door only checks that it's a real card.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app/posts/actions.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="s1"&gt;'use server'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zod'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;auth&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/lib/auth'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/lib/db'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;deletePost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rawId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Please sign in.'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cuid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;safeParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rawId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Invalid post.'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deleteMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Post not found.'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;auth() checks that someone is logged in, inside the action itself. A check on the page doesn't protect the actions on it, because the action can be called directly.&lt;/li&gt;
&lt;li&gt;The ID goes through a schema, same rule as before. It comes from the client, so it's hostile.&lt;/li&gt;
&lt;li&gt;This is the line that matters: where has both id and authorId. If the post belongs to someone else, nothing matches and nothing is deleted. Remove authorId and any logged-in user can delete any post by trying IDs.&lt;/li&gt;
&lt;li&gt;deleteMany instead of delete is deliberate. It returns a count rather than throwing when nothing matches, and it lets you filter on the owner directly.&lt;/li&gt;
&lt;li&gt;The same error comes back for "doesn't exist" and "isn't yours", so an attacker can't use it to discover which IDs are real.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From the docs: &lt;a href="https://nextjs.org/docs/app/guides/data-security" rel="noopener noreferrer"&gt;A check on the page doesn't protect the actions on it&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hiding a button isn't security. It's decoration. The server checks every time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Secrets: assume a leak is permanent
&lt;/h3&gt;

&lt;p&gt;A secret is any key that proves you're you to another service: your Stripe key, your database URL. There's no upper limit on what a leak can cost. If you push one to a public repository, deleting the commit doesn't fix it. &lt;a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository" rel="noopener noreferrer"&gt;GitHub's own advice&lt;/a&gt; starts with revoking or rotating the secret, because copies may exist elsewhere. Rotating means replacing the key with a new one and killing the old one. So if you even suspect a leak, rotate first and think later.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lib/env.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zod'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="no"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;STRIPE_SECRET_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'sk_'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;STRIPE_WEBHOOK_SECRET&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'whsec_'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;RESEND_API_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;safeParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`Bad environment:\n${z.prettifyError(result.error)}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This schema treats your configuration as outside data, because it is. Your hosting dashboard is a trust boundary too, and a typo there is just as real.&lt;/li&gt;
&lt;li&gt;startsWith('sk_') catches a classic mistake: pasting your public key where the secret one should go. If you use Stripe's restricted keys, they start with rk_, so adjust this.&lt;/li&gt;
&lt;li&gt;z.prettifyError builds a readable list of what's wrong. It names the variable and the problem, and it doesn't print the value, which is exactly what you want in a build log.&lt;/li&gt;
&lt;li&gt;export const env gives the rest of your app typed values. Import env everywhere instead of touching process.env, and the compiler knows these strings exist.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On its own, that file only fails when something first imports it, and that might be a user's request. So make the build load it, right here, along with your security headers.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;next.config.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;NextConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'next'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s1"&gt;'./lib/env'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;NextConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'/:path*'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Strict-Transport-Security'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'max-age=63072000; includeSubDomains'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'X-Content-Type-Options'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'nosniff'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Content-Security-Policy'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"frame-ancestors 'none'"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Referrer-Policy'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'strict-origin-when-cross-origin'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;import './lib/env' runs the check while the build loads this config. With the variables missing, next build stops right away and lists all four; with valid values it finishes normally. That's a bad deploy caught at your desk instead of by a customer.&lt;/li&gt;
&lt;li&gt;Strict-Transport-Security tells browsers to use HTTPS only, for two years here. Be careful: includeSubDomains covers every subdomain, so make sure they all have HTTPS first. This setting is hard to take back, because browsers remember it.&lt;/li&gt;
&lt;li&gt;X-Content-Type-Options: nosniff stops browsers from guessing file types, which closes a trick where an uploaded file gets run as a script.&lt;/li&gt;
&lt;li&gt;frame-ancestors 'none' stops other sites from embedding yours in an invisible frame to trick people into clicking things. Remove it if you actually need to be embedded.&lt;/li&gt;
&lt;li&gt;Referrer-Policy limits how much of your URLs is passed along to other sites.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Plan B: if your build server doesn't have your production secrets, as in some Docker setups, this import will fail every build. In that case, remove it from next.config.ts and import lib/env.ts in your server code instead, so the check runs when the server first needs it. A full Content Security Policy is a bigger project than the one line here, so read the Next.js guide before you start.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The rest of the boring list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;.env goes into .gitignore before your first commit, and .env.example holds placeholders only. Turn on GitHub's push protection too, which blocks recognized secrets before they reach the repository.&lt;/li&gt;
&lt;li&gt;Use separate keys per environment: Stripe test keys on your laptop, live keys only in your host's settings.&lt;/li&gt;
&lt;li&gt;Anything starting with NEXT_PUBLIC_ is copied into the JavaScript sent to the browser. By definition, it isn't a secret.&lt;/li&gt;
&lt;li&gt;Session cookies are HttpOnly, Secure and SameSite: JavaScript can't read them, they only travel over HTTPS, and other sites can't easily send them along.&lt;/li&gt;
&lt;li&gt;Passwords are hashed, and you never invent your own scheme. OWASP's first choice is Argon2id; bcrypt is meant for older systems, with a work factor of at least 10 and a 72-byte input limit. Better yet, use an auth library that handles this, plus resets and sessions, for you.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From the docs: &lt;a href="https://docs.github.com/en/code-security/secret-scanning/introduction/about-push-protection" rel="noopener noreferrer"&gt;GitHub's push protection&lt;/a&gt;, &lt;a href="https://nextjs.org/docs/app/guides/environment-variables" rel="noopener noreferrer"&gt;copied into the JavaScript sent to the browser&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies" rel="noopener noreferrer"&gt;HttpOnly, Secure and SameSite&lt;/a&gt;, &lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html" rel="noopener noreferrer"&gt;OWASP's first choice is Argon2id&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That password reset question I never asked myself? &lt;a href="https://codefromscratch.org/blog/nextauth-vs-lucia-vs-better-auth?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;A good auth library&lt;/a&gt; answers most of it. This is why I say you don't need to invent it. You need to know that it has to exist.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Your code can be replaced. Your data can't.
&lt;/h2&gt;

&lt;p&gt;On your laptop, the database is disposable. Change the schema, wipe it, fill it back up. The day real users exist, that's over. If you deploy bad code, you redeploy old code. If you delete data, it's gone unless you have a backup that works.&lt;/p&gt;

&lt;p&gt;A migration is a small script that changes your database's structure, kept in git along with your code. Here's the classic trap. You rename a column from name to fullName, and you assume the tool will rename it. It can't read your mind. It sees one column disappear and another appear, and &lt;a href="https://www.prisma.io/docs/orm/v6/prisma-migrate/workflows/customizing-migrations" rel="noopener noreferrer"&gt;Prisma's docs say so plainly&lt;/a&gt;: by default a rename creates a new column and drops the old one, along with its data. You get something like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;migration.sql&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="s2"&gt;"User"&lt;/span&gt; &lt;span class="k"&gt;DROP&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="s2"&gt;"fullName"&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run that on a Postgres table with two users and, because of NOT NULL, it fails and nothing changes: "column fullName of relation User contains null values". That's the lucky version. Make the new column optional and it runs with no complaint, and both users now have a fullName of null. Their names are gone. Same harmless-looking change, and the second version you wouldn't notice until someone complained.&lt;/p&gt;

&lt;p&gt;For a simple rename you can edit the file. Run prisma migrate dev --create-only, which writes the migration without applying it, and replace those lines with a RENAME COLUMN. But a straight rename still has a problem for a live app: during a deploy, the old code and the new code run at the same time for a moment. The old code asks for name, the column is gone, and you get errors. That's why careful teams use expand and contract, which turns one risky change into three safe ones.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;expand-and-contract.sql&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Step 1, expand: add the new column. Old code keeps working.&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="s2"&gt;"User"&lt;/span&gt; &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="s2"&gt;"fullName"&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Step 2, migrate: new code writes both columns. Then copy old rows.&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="s2"&gt;"User"&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="s2"&gt;"fullName"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"name"&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="s2"&gt;"fullName"&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Step 3, contract: only when nothing reads "name" anymore.&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="s2"&gt;"User"&lt;/span&gt; &lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="s2"&gt;"fullName"&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="s2"&gt;"User"&lt;/span&gt; &lt;span class="k"&gt;DROP&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step 1 adds the column as optional, so it can't fail on existing rows, and old code simply ignores it. Deploy this alone.&lt;/li&gt;
&lt;li&gt;Next you deploy code that writes to both columns and reads from the new one. This part isn't in the SQL, and it's the part people forget.&lt;/li&gt;
&lt;li&gt;Step 2 copies the old values. The WHERE means it only touches rows that still need it, so you can safely run it again if it stops halfway.&lt;/li&gt;
&lt;li&gt;Step 3 happens in a later deploy, after you've verified nothing reads the old column. SET NOT NULL is the rule you wanted all along, added once the data can satisfy it. Then, and only then, the drop.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run all three steps on the same two users, and both names end up in fullName with nothing lost. It feels slow the first time. It's much faster than restoring a backup while your users watch. It's like moving house: you bring your things to the new place first, and you hand back the old keys only when the old place is empty.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For advanced readers: on a big table, the danger shifts from data to locks. ALTER TABLE takes an ACCESS EXCLUSIVE lock by default, and a normal CREATE INDEX blocks writes until it's done, so use CREATE INDEX CONCURRENTLY for live tables, which can't run inside a transaction. Adding a column with a non-volatile default doesn't rewrite the table in current PostgreSQL, while a volatile default does. And a backfill on millions of rows should run in small batches.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The commands here are for Prisma 7, where prisma migrate deploy applies migrations in production. Prisma 8 is at release candidate as I write this and &lt;a href="https://www.prisma.io/docs/guides/database/data-migration" rel="noopener noreferrer"&gt;its guide uses a different command&lt;/a&gt;, so match the docs to your version. The basics are in &lt;a href="https://codefromscratch.org/blog/prisma-orm-from-zero-to-production?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;the Prisma guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Good enough: migrations live in git and run as part of your deploy, never typed by hand against production. You read every generated migration before it runs, because the tool compares structure, not intent. And you've restored a backup at least once, on purpose, so that the first time isn't during an emergency. Your &lt;a href="https://codefromscratch.org/blog/managed-postgres-comparison?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;Postgres provider&lt;/a&gt; decides what backups you get, so check that before you need them.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. The database being down shouldn't mean a blank page
&lt;/h2&gt;

&lt;p&gt;Every service you depend on will be unavailable at some point. The hobby default is that any failure takes the whole page down: the database hiccups, and someone who only wanted to read your About page sees an error. Your weakest dependency has set the uptime of your entire site.&lt;/p&gt;

&lt;p&gt;A shop whose card reader dies doesn't lock its doors. It puts up a sign and takes cash. Graceful degradation is the same idea: when one part fails, the rest keeps working, and you decide in advance what the fallback is.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lib/catalog.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/lib/db'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;log&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/lib/log'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getFeaturedProducts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;published&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'error'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'featured products unavailable'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This looks like what I told you not to do in section 2, so what's different? It's a decision, and it isn't silent. The fallback is chosen on purpose and the failure gets logged. That's the "log and fall back on purpose" option.&lt;/li&gt;
&lt;li&gt;return [] means the page renders with an empty shelf. Your page has to handle that well, with a message like "Featured products are unavailable right now", not a blank gap.&lt;/li&gt;
&lt;li&gt;log('error', ...) means you find out. Without it, you've built the lying form from section 2 with extra steps.&lt;/li&gt;
&lt;li&gt;await in return await matters. Without it, the promise is returned before it fails, and this catch never runs.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; For advanced readers, three traps. One: on a statically cached page, that empty fallback can get cached too, so a brief database blip turns into an empty shelf until the next revalidation. Don't let pages that matter cache a failure. Two: a sleeping database often doesn't fail, it hangs, so without a timeout, your fallback never fires. Three: Next.js uses thrown errors internally for redirect() and notFound(), and those must not be swallowed by your catch. Keep those calls outside the try, or call unstable_rethrow(error) first in the catch.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So ask it for each dependency, one by one. Database down: which pages still render, and what do the rest show? Email provider down: does signup fail, or does the welcome email wait and retry? Payment provider down: does the site break, or only the checkout button? If you don't answer these now, production answers them for you.&lt;/p&gt;

&lt;p&gt;Good enough: public content pages survive a database outage, every fallback logs what it's absorbing, and no outage can take down a page that doesn't actually need that service. And when a deploy itself is what broke, you want &lt;a href="https://codefromscratch.org/blog/rollback-without-feature-flags?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;a rollback plan&lt;/a&gt; you've thought about before the bad day.&lt;/p&gt;

&lt;h2&gt;
  
  
  So that's all it is
&lt;/h2&gt;

&lt;p&gt;Read back through the eight sections and notice what they share. None of this shows up in a demo. Every item is invisible right until it's the only thing that matters. That's why tutorials skip it, and it's why "it works" is the cheapest sentence in software.&lt;/p&gt;

&lt;p&gt;But look at the code we wrote. A schema. A try/catch that tells the truth. A counter. A random ID. A few tests. One extra condition on a query. A column added before another gets dropped. None of that is genius, and there's no secret senior knowledge in it. Production-grade is just the happy path plus honest answers to eight questions. You've written harder code than this already.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to be careful about, and the Plan B
&lt;/h2&gt;

&lt;p&gt;The biggest mistake with a list like this is treating it as all or nothing. It can stop you from shipping at all. So here's how to size it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Personal site, no logins, no money: keep your secrets out of git and validate your forms. Honestly, the rest is mostly overkill. Ship it.&lt;/li&gt;
&lt;li&gt;Real users with accounts: everything in sections 1, 2, 3 and 6 before you launch. Add logging the week you launch.&lt;/li&gt;
&lt;li&gt;Money involved: all eight, plus tests on checkout and verified webhooks.&lt;/li&gt;
&lt;li&gt;Short on time before a launch: do validation and authorization first, since those are the holes attackers can use today. Logging is next, because it's how you'll learn about everything else.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And if you don't understand a piece of this, don't paste it and hope. If your Plan B is hope, that's not a Plan B. Ask what the line does, change it, break it on purpose, and watch what happens. I learned by trying things and by making mistakes, and a mistake on a test project is free.&lt;/p&gt;

&lt;h2&gt;
  
  
  The checklist
&lt;/h2&gt;

&lt;p&gt;Here's the whole article as a review you can run on your app. Mark each line as handled on purpose, handled by accident, or not handled. Only the first one counts.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every Server Action and route handler parses its input with a schema&lt;/li&gt;
&lt;li&gt;Prices, roles and other users' IDs never come from the client&lt;/li&gt;
&lt;li&gt;Webhook signatures are verified before the payload is believed&lt;/li&gt;
&lt;li&gt;Zero empty catch blocks, and an error.tsx on every major section&lt;/li&gt;
&lt;li&gt;Login, email and paid endpoints are rate limited in shared storage and return 429 with Retry-After&lt;/li&gt;
&lt;li&gt;Logs are structured, carry a request ID, and hold no secrets&lt;/li&gt;
&lt;li&gt;Error tracking tells you about new failures before users do&lt;/li&gt;
&lt;li&gt;Tests cover pricing, permissions and checkout, and every fixed bug gets a test&lt;/li&gt;
&lt;li&gt;Every query on private data is scoped to its owner on the server&lt;/li&gt;
&lt;li&gt;.env has never touched git, config is validated at build time, and live keys exist only on your host&lt;/li&gt;
&lt;li&gt;Security headers are set, and session cookies are HttpOnly, Secure and SameSite&lt;/li&gt;
&lt;li&gt;Migrations are read before they run, and destructive changes use expand and contract&lt;/li&gt;
&lt;li&gt;You've restored a backup at least once, on purpose&lt;/li&gt;
&lt;li&gt;Public pages render with the database down, and each dependency has a decided failure mode&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you score low, that's not a verdict on you. It's a verdict on what you were taught.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to learn next
&lt;/h2&gt;

&lt;p&gt;This article is the map, and most sections have a guide that goes deeper. Here's the order I'd take them in. If the bigger picture of how these tools fit together is still fuzzy, read &lt;a href="https://codefromscratch.org/blog/modern-full-stack-2026?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;the full-stack walkthrough&lt;/a&gt; first.&lt;/p&gt;

&lt;p&gt;Start with &lt;a href="https://codefromscratch.org/blog/zod-at-trust-boundaries?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;Zod at trust boundaries&lt;/a&gt;, because it removes the biggest class of bugs for the least effort. Then make failure a designed state with &lt;a href="https://codefromscratch.org/blog/error-boundaries-done-right?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;error boundaries&lt;/a&gt;. Before anything goes public, add &lt;a href="https://codefromscratch.org/blog/api-rate-limiting-nextjs?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;rate limiting&lt;/a&gt;, since bots won't wait for you to be ready. The week you launch, add &lt;a href="https://codefromscratch.org/blog/structured-logging-nextjs?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;structured logging&lt;/a&gt;. The day money enters the picture, &lt;a href="https://codefromscratch.org/blog/stripe-webhook-verification?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;Stripe webhook verification&lt;/a&gt; stops being optional, and &lt;a href="https://codefromscratch.org/blog/stripe-nextjs-setup?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;the Stripe setup guide&lt;/a&gt; covers the rest. When all of that is done, &lt;a href="https://codefromscratch.org/blog/ship-nextjs-production?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;the production launch playbook&lt;/a&gt; picks up where this article ends: deploys, DNS, monitoring and launch day.&lt;/p&gt;

&lt;p&gt;Now the honest exercise. Take the app you have right now and walk the checklist. One section a week is plenty, and a little most days beats a heroic weekend followed by a month off. Take a day or two off when it isn't going in, just don't let the breaks get long. 1% a day adds up to more than you'd think, and you don't have to know all of this yet. Plenty of people working in companies don't know everything either, and they ask for help.&lt;/p&gt;

&lt;p&gt;You can do this, and you have to. If you weren't capable, I wouldn't spend my time on you. Just don't give up, and you'll always have me on your side.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/production-grade-code-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=production-grade-code-checklist"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Vibe Coding Is Fine Until It Isn't: A 12-Point Production Checklist</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Fri, 13 Nov 2026 22:46:01 +0000</pubDate>
      <link>https://dev.to/codefromscratch/vibe-coding-is-fine-until-it-isnt-a-12-point-production-checklist-43ld</link>
      <guid>https://dev.to/codefromscratch/vibe-coding-is-fine-until-it-isnt-a-12-point-production-checklist-43ld</guid>
      <description>&lt;p&gt;You built an app with an AI tool, it works when you click through it, and now you're wondering whether it's safe to let real people sign up. That's the right question to ask, and today you get a way to answer it: twelve checks, each with the failure it prevents and a test you can run yourself in about five minutes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is vibe coding safe?&lt;/strong&gt; For a prototype, usually yes. For an app with real users, real data or real money, it's safe only after you've checked the places where generated code tends to break: secrets, who can read whose data, input from the browser, abuse, payments, errors, dependencies and tests. This article gives you one test for each.&lt;/p&gt;

&lt;p&gt;If you're a beginner, don't panic about the length. Read the short story of each check, run the test, and write down what failed. You don't have to understand every fix today; you have to know where the holes are. If you already ship code for a living, the scripts are the part worth copying, and the advanced bits sit in the callouts and in the section on running the whole thing with an AI agent.&lt;/p&gt;

&lt;p&gt;If you haven't read it yet, &lt;a href="https://codefromscratch.org/blog/what-is-vibe-coding?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;What Is Vibe Coding? Where It Works and Where It Breaks&lt;/a&gt; explains the idea and shows one bug in detail. This one is the practical follow-up: the full inspection.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Tested with: Node 26.13 on 2026-11-11. Every script in this article was run against a small local test server that has two versions of each route, the kind of code an AI tool hands you on the first try and a fixed one. The outputs you see below are copied from those runs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A demo and a product are different things
&lt;/h2&gt;

&lt;p&gt;Here's the problem in your own words: "It works. I clicked everything. Nothing crashed. So is it done?"&lt;/p&gt;

&lt;p&gt;It works for you. That's the catch. When you test your own app, you are the nicest user it will ever have. You sign in with one account, you type sensible things into the forms, you click the buttons in the order you designed them, and you never try to read somebody else's data, because why would you? Real traffic is not that polite. Some of it is curious people, some of it is bots, and a small part of it is someone actively looking for the one route you forgot to protect.&lt;/p&gt;

&lt;p&gt;Think about buying a house. A house can look finished: fresh paint, nice kitchen, lights on. An inspector doesn't admire the living room. The inspector turns on every tap at once, flips the breakers, looks under the sink and climbs into the attic. The question isn't whether the house is pretty. It's what happens when the house is used hard. That's the job we're doing today, on your app.&lt;/p&gt;

&lt;p&gt;Is this a real problem or just fear? Here are two sources worth reading. Veracode, a company that sells code security scanning (so read it as a vendor's report), tested code from over 100 language models and says &lt;a href="https://www.veracode.com/resources/analyst-reports/2025-genai-code-security-report/" rel="noopener noreferrer"&gt;AI-generated code introduced risky security flaws in 45% of tests&lt;/a&gt;. And the &lt;a href="https://top10.owasp.org/2025" rel="noopener noreferrer"&gt;OWASP Top 10:2025&lt;/a&gt;, the list most security people use as a starting point, puts Broken Access Control at number one, which is exactly the "Emily can read James's order" bug you'll see in a minute. Software supply chain failures are number three. Both show up in this checklist.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why AI-built apps break in the same places
&lt;/h2&gt;

&lt;p&gt;Why does this happen? Good question, because it's not that the AI is stupid.&lt;/p&gt;

&lt;p&gt;A model writes the code you asked for. If you asked for "a page that shows the order", you get a page that shows the order. It works. What you didn't say, it fills in with an assumption, and the most common assumption is the friendly one: whoever asks for order 1002 must be the owner of order 1002. The model can't see your users. It can't know that one of them will change a number in the address bar.&lt;/p&gt;

&lt;p&gt;I'll be honest about how I see it. I check what AI writes as far as I can, because it can hallucinate or assume things it should not. And when the output isn't what I imagined, usually I could have prompted better. The AI is a machine running maths. It can't know what's in my head, and it definitely can't know the bad intentions of a stranger who hasn't shown up yet.&lt;/p&gt;

&lt;p&gt;There's also a second cause, and it's ours, not the model's. We test by clicking. Clicking only tests the happy path, the one where everybody behaves. Every check below is a way to stop being the nice user for five minutes.&lt;/p&gt;

&lt;p&gt;I didn't think about any of this when I started. I never asked what happens when a thousand people have profiles in my app: how their accounts are protected, how a password reset works, what I do when my own bug hurts them. Those questions come for every app that gets real users. Better to meet them now, on your terms.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use this checklist
&lt;/h2&gt;

&lt;p&gt;The checklist has twelve items in eight groups: secrets, access, input, abuse, payments, failure, dependencies and tests. Each item answers three questions. What breaks if you skip it? What's the five-minute test? Where do you learn the fix?&lt;/p&gt;

&lt;p&gt;Most tests are tiny Node scripts. You need Node 20 or newer: the scripts use fetch, which is built into Node, and a recursive folder read that older versions lack. Create a folder called checks in your project, save the scripts there, start your app locally with npm run dev, and run each one with node checks/&amp;lt;name&amp;gt;.mjs. The scripts talk to &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; by default; set BASE_URL if your app runs somewhere else.&lt;/p&gt;

&lt;p&gt;Some tests need you to be signed in. Here's the trick. Create two test accounts in your own app, say Emily (&lt;a href="mailto:demo@example.com"&gt;demo@example.com&lt;/a&gt;) and James. Sign in as Emily, open the browser's developer tools, go to the storage or application tab, find the session cookie and copy its name and value. That string, like name=value, goes into the EMILY_COOKIE variable. Now your script is Emily.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Only run these tests against apps you own, on your own machine or your own staging site. Sending forged requests or hammering the login of someone else's app is not a test, it's an attack, and it can be illegal. Your app, your accounts, your responsibility.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Secrets: the keys that must never leave the server
&lt;/h2&gt;

&lt;p&gt;A secret is anything that proves to another service that you are you: a Stripe secret key, a database password, a private key, an email provider's API key. Whoever has it can act as your app. They can read your database, issue refunds, send email in your name. So secrets live in exactly one place: environment variables on the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. No secret lives in your code
&lt;/h3&gt;

&lt;p&gt;What breaks: an AI tool, asked to "connect Stripe", sometimes pastes the key right into a file so the example works. You push to GitHub. If the repository is public, the key is public. If it's private, the key is still in every copy and every backup of the code, forever.&lt;/p&gt;

&lt;p&gt;The test: scan your project for the shapes secrets usually have.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;checks/find-secrets.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;readdirSync&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;statSync&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:fs"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;join&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:path"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s2"&gt;"."&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;patterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;sk_live_&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;zA&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Z&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;             &lt;span class="c1"&gt;// Stripe secret key, live&lt;/span&gt;
  &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;sk_test_&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;zA&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Z&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;             &lt;span class="c1"&gt;// Stripe secret key, test&lt;/span&gt;
  &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;whsec_&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;zA&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Z&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;               &lt;span class="c1"&gt;// Stripe webhook signing secret&lt;/span&gt;
  &lt;span class="o"&gt;/-----&lt;/span&gt;&lt;span class="no"&gt;BEGIN&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Z&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="no"&gt;PRIVATE&lt;/span&gt; &lt;span class="no"&gt;KEY&lt;/span&gt;&lt;span class="o"&gt;-----/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// any private key&lt;/span&gt;
  &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nf"&gt;postgres&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ql&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt;\&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;^:&lt;/span&gt;\&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+:&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;@\&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;@&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// database URL with a password in it&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nf"&gt;readdirSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;recursive&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;^|&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\\&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node_modules&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;git&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\\&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;$&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;statSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isDirectory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"utf8"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;patterns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${path}:${i + 1}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Line by line. The first two lines bring in Node's file tools. root is the folder to scan; it's the current folder unless you pass another one. The patterns array is the heart of the script: each line is a regular expression, a search pattern, for one kind of secret. sk_live_ and sk_test_ are how Stripe secret keys start, whsec_ is how Stripe webhook signing secrets start, BEGIN ... PRIVATE KEY is the header of any private key file, and the last one catches a database address with a password inside it, like postgresql://user:password@host.&lt;/p&gt;

&lt;p&gt;The loop walks through every file in every subfolder (that's what recursive: true does). It skips node_modules, which is other people's code, and .git, which is git's own storage. For every other file it reads the text, splits it into lines and prints the file name and line number of any line that matches. It never prints the secret itself, because you don't want your keys in a terminal history either.&lt;/p&gt;

&lt;p&gt;Here's what it printed on the test project:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ node checks/find-secrets.mjs
.env.local:1
.env.local:2
lib/stripe.ts:1
.next/static/chunks/page-abc.js:1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read the result like this. Hits in .env.local are fine, as long as git ignores that file; check that .gitignore contains .env*.local or .env*. Any other hit is a leak. lib/stripe.ts has a key typed straight into the code. And the hit in .next/static is the next check's problem, so hold that thought.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; If a real key was ever committed, deleting the line is not enough. GitHub's own guide says the first step is to revoke or rotate the secret, because rewriting history may not remove copies in forks, clones and caches. Rotate first, clean up second. Your old key must stop working; that's the only fix that holds.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Read GitHub's guide on &lt;a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository" rel="noopener noreferrer"&gt;removing sensitive data from a repository&lt;/a&gt; once, before you need it. And search your history too, not only today's files: a key that was in the code last month and deleted since is still sitting in an old commit.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. No secret reaches the browser
&lt;/h3&gt;

&lt;p&gt;What breaks: in Next.js, an environment variable whose name starts with NEXT_PUBLIC_ is copied into the JavaScript that every visitor downloads. The &lt;a href="https://nextjs.org/docs/app/guides/environment-variables" rel="noopener noreferrer"&gt;Next.js docs&lt;/a&gt; say it plainly: the value is "inlined into any JavaScript sent to the browser". Variables without the prefix stay on the server.&lt;/p&gt;

&lt;p&gt;Here's how a secret ends up public. A component in the browser needs data, the code reads process.env.STRIPE_SECRET_KEY, and it comes back undefined, because the browser can't see server variables. You paste the error into the chat. The quickest change that makes the error go away is renaming the variable to NEXT_PUBLIC_STRIPE_SECRET_KEY. It works. And your secret key is now in a file anyone can open with View Source.&lt;/p&gt;

&lt;p&gt;The test: build the app, then look for the value of every server secret inside the files the browser gets.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;checks/bundle-leak.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;readdirSync&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;statSync&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:fs"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;join&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:path"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;secrets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".env.local"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"utf8"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Z0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9_&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"']?(.+?)["&lt;/span&gt;&lt;span class="s1"&gt;']?$/))
  .filter((m) =&amp;gt; m &amp;amp;&amp;amp; !m[1].startsWith("NEXT_PUBLIC_") &amp;amp;&amp;amp; m[2].length &amp;gt;= 8)
  .map((m) =&amp;gt; ({ name: m[1], value: m[2] }));

let leaks = 0;
for (const file of readdirSync(".next/static", { recursive: true })) {
  const path = join(".next/static", file);
  if (statSync(path).isDirectory()) continue;
  const text = readFileSync(path, "utf8");
  for (const s of secrets) {
    if (text.includes(s.value)) {
      console.log(`LEAK  ${s.name} is inside ${path}`);
      leaks++;
    }
  }
}
console.log(`${secrets.length} server secrets checked, ${leaks} found in browser files`);
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first statement reads .env.local and turns it into a list. For each line, the regular expression pulls out a NAME=value pair and strips quotes. The filter keeps only server secrets: names that don't start with NEXT_PUBLIC_ (those are public on purpose) and values of at least eight characters, so a setting like PORT=3000 doesn't count as a secret and doesn't match half the internet.&lt;/p&gt;

&lt;p&gt;Then the loop goes through every file in .next/static. That folder is what next build produces for the browser: every chunk of JavaScript a visitor can download. For each file and each secret it asks one question, does this file contain this exact value? If yes, it prints which secret and where. At the end you get a count.&lt;/p&gt;

&lt;p&gt;Run npm run build first, then node checks/bundle-leak.mjs from the project root. On the test project:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ node checks/bundle-leak.mjs
LEAK  STRIPE_SECRET_KEY is inside .next/static/chunks/page-abc.js
2 server secrets checked, 1 found &lt;span class="k"&gt;in&lt;/span&gt; browser files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fix is never "hide it better". The fix is moving the work that needs the secret to the server: a route handler or a server action calls Stripe, and the browser only gets the result. If a value really must be in the browser, like a publishable Stripe key or an analytics id, it's not a secret, and the service that issued it says so in its docs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Access: every request proves whose data it is
&lt;/h2&gt;

&lt;p&gt;This is the big one. If you do only one check today, do this one.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Emily can't read James's order
&lt;/h3&gt;

&lt;p&gt;Some words first. Authentication answers "who are you?" It's the login. Authorization answers "are you allowed to touch this?" Generated code is usually good at the first and quietly skips the second. The route checks that someone is signed in, then returns whatever id was asked for.&lt;/p&gt;

&lt;p&gt;Security people call this an IDOR, an insecure direct object reference. Fancy name, simple bug: the id in the address is the only thing standing between a user and somebody else's data. Change 1001 to 1002 and you're reading a stranger's order, email and home address.&lt;/p&gt;

&lt;p&gt;Click around in the demo below. You're signed in as Emily. Ask for her order 1001, then try 1002, then switch the server to the fixed version and try again.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; Two accounts, one URL: the IDOR check. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/vibe-coding-production-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Notice that both servers check the login. The generated one is not missing security; it's missing one question. The fixed one asks it: who owns this order? And when the answer is "not you", it says 404, not found, instead of 403, forbidden. Why? Because 403 tells a curious visitor that order 1002 exists. 404 tells them nothing.&lt;/p&gt;

&lt;p&gt;The test for your real app needs your two test accounts. As James, create something: an order, a note, a profile, whatever your app stores. Write down its id from the address bar or the network tab. Then run this as Emily:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;checks/two-accounts.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BASE_URL&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s2"&gt;"http://localhost:3000"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;emily&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;EMILY_COOKIE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// copied from the browser, signed in as Emily&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;jamesOrder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;JAMES_ORDER&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// an id that belongs to James&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${BASE}/api/orders/${jamesOrder}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;emily&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`FAIL  Emily can read James's order (status ${res.status})`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exitCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`OK    the server refused with status ${res.status}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;BASE is your app's address. emily is Emily's session cookie, the name=value string from the developer tools. jamesOrder is the id of something that belongs to James. The fetch call asks for James's thing while carrying Emily's cookie, which is exactly what a browser would send if Emily typed that address herself.&lt;/p&gt;

&lt;p&gt;res.ok is true for any status from 200 to 299, meaning the server handed the data over. That's a fail, so the script prints the status and the first 200 characters of what leaked, and sets the exit code to 1, which matters later when you run checks automatically. Any other status means the server refused, and that's what you want.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# against the route as generated&lt;/span&gt;
$ node checks/two-accounts.mjs
FAIL  Emily can &lt;span class="nb"&gt;read&lt;/span&gt; James&lt;span class="s1"&gt;'s order (status 200)
{"id":1002,"owner":"james","item":"Team plan","total":3000,"address":"12 Elm Street"}

# against the fixed route
$ node checks/two-accounts.mjs
OK    the server refused with status 404
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Repeat it for every route that takes an id: orders, invoices, messages, files, settings, and every update and delete, not only reads. The fix is one idea: the database query includes the owner, so the row can only be found by the person it belongs to. &lt;a href="https://codefromscratch.org/blog/what-is-vibe-coding?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;What Is Vibe Coding&lt;/a&gt; shows that fix on a real route handler, and &lt;a href="https://codefromscratch.org/blog/production-grade-code-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Production-Grade Code&lt;/a&gt; covers the version that bites on updates: checking who, but not whose.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Using Supabase, where the browser talks to the database directly? Then the database itself has to say no. Supabase's docs are clear: a table in an exposed schema without Row Level Security "is readable and writable by any role with a grant on it", and they ask you to enable RLS on every such table. Check each table in the dashboard. A table with RLS switched off and the public key in your front end is the IDOR bug with the door already open.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The Supabase line above comes from its &lt;a href="https://supabase.com/docs/guides/database/postgres/row-level-security" rel="noopener noreferrer"&gt;Row Level Security guide&lt;/a&gt;. If you're on Supabase auth, &lt;a href="https://codefromscratch.org/blog/supabase-authentication-complete-guide-with-next-js?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;the Supabase authentication guide&lt;/a&gt; shows where the policies go.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. The server decides prices and roles, never the browser
&lt;/h3&gt;

&lt;p&gt;What breaks: the checkout form sends the plan and the price, and the server charges whatever price arrives. Or the sign-up form sends role: "user" and the server saves whatever role arrives. Anyone can edit a request before it leaves the browser; it takes no special tools. So a price or a role coming from the browser is a suggestion from a stranger.&lt;/p&gt;

&lt;p&gt;The test for this one is the same script as the next check, so let's look at them together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Input: garbage in, a polite 400 out
&lt;/h2&gt;

&lt;h3&gt;
  
  
  5. Every input is checked at the door
&lt;/h3&gt;

&lt;p&gt;What breaks: the server assumes the body is what the form would have sent. Send it something else, a number where text belongs or no JSON at all, and the code crashes halfway through. A crash is a 500 error, and on many setups the error message, sometimes with the full stack trace, goes straight back to the visitor.&lt;/p&gt;

&lt;p&gt;The test: send your own checkout or sign-up endpoint four requests that a normal form would never send.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;checks/bad-input.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BASE_URL&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s2"&gt;"http://localhost:3000"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cookie&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;EMILY_COOKIE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cases&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"price from the browser"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"pro"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"extra field"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"pro"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"admin"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"wrong type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"not JSON at all"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;cases&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${BASE}/api/checkout`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"content-type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cookie&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;leaks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;bat&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;+:&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+:&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+|&lt;/span&gt;&lt;span class="n"&gt;prisma&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="no"&gt;ECONNREFUSED&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${name.padEnd(24)} ${res.status}  ${text.slice(0, 60).replace(/\s+/g, " ")}${leaks ? "  &amp;lt;- LEAKS INTERNALS" : ""}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;cases is a list of pairs: a name for the output, and the body to send. The first sends a price of 1 cent. The second sneaks in role: "admin". The third sends a number where the plan name should be. The fourth isn't JSON at all, just the word hello.&lt;/p&gt;

&lt;p&gt;The loop posts each one as Emily, with the content-type header saying JSON. If the body is already a string, it goes as it is; otherwise JSON.stringify turns the object into JSON text. Then the script reads the answer as text and runs one more regular expression over it, looking for things that should never reach a visitor: a stack trace line (at something:12:34), the word prisma, a database connection error, a TypeError. Each result prints on one line: name, status, the start of the response, and a warning if internals leaked. The replace call squeezes line breaks into spaces so a multi-line stack trace stays on one line.&lt;/p&gt;

&lt;p&gt;Here's the version the AI wrote, then the fixed one:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# as generated&lt;/span&gt;
price from the browser   200  &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"plan"&lt;/span&gt;:&lt;span class="s2"&gt;"PRO"&lt;/span&gt;,&lt;span class="s2"&gt;"amount"&lt;/span&gt;:1,&lt;span class="s2"&gt;"role"&lt;/span&gt;:&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
extra field              200  &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"plan"&lt;/span&gt;:&lt;span class="s2"&gt;"PRO"&lt;/span&gt;,&lt;span class="s2"&gt;"amount"&lt;/span&gt;:1200,&lt;span class="s2"&gt;"role"&lt;/span&gt;:&lt;span class="s2"&gt;"admin"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
wrong &lt;span class="nb"&gt;type&lt;/span&gt;               500  TypeError: body.plan.toUpperCase is not a &lt;span class="k"&gt;function&lt;/span&gt; at Se  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;- LEAKS INTERNALS
not JSON at all          500  SyntaxError: Unexpected token &lt;span class="s1"&gt;'h'&lt;/span&gt;, &lt;span class="s2"&gt;"hello"&lt;/span&gt; is not valid JSON  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;- LEAKS INTERNALS

&lt;span class="c"&gt;# fixed&lt;/span&gt;
price from the browser   200  &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"plan"&lt;/span&gt;:&lt;span class="s2"&gt;"pro"&lt;/span&gt;,&lt;span class="s2"&gt;"amount"&lt;/span&gt;:1200&lt;span class="o"&gt;}&lt;/span&gt;
extra field              200  &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"plan"&lt;/span&gt;:&lt;span class="s2"&gt;"pro"&lt;/span&gt;,&lt;span class="s2"&gt;"amount"&lt;/span&gt;:1200&lt;span class="o"&gt;}&lt;/span&gt;
wrong &lt;span class="nb"&gt;type&lt;/span&gt;               400  &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;:&lt;span class="s2"&gt;"Unknown plan"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
not JSON at all          400  &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;:&lt;span class="s2"&gt;"Invalid JSON"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look at the first two lines of the generated version. The order went through for 1 cent, and Emily is now an admin. Two lines of output, two disasters. In the fixed version the price comes from the server's own price list, the extra field is ignored, and the broken requests get a 400 with a short, boring message. Boring is the goal.&lt;/p&gt;

&lt;p&gt;That's checks 4 and 5 in one script. The fix has a name: validation at the trust boundary. The boundary is the line where data comes from somewhere you don't control. &lt;a href="https://codefromscratch.org/blog/zod-at-trust-boundaries?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Zod at the Trust Boundary&lt;/a&gt; shows how to describe what you accept in one schema and refuse everything else, and &lt;a href="https://codefromscratch.org/blog/login-form-validation-client-and-server?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Login Form Validation: Why You Check Twice&lt;/a&gt; explains why the check in the browser is for the user's comfort and the check on the server is for your safety.&lt;/p&gt;

&lt;h2&gt;
  
  
  Abuse: what happens when someone tries a thousand times
&lt;/h2&gt;

&lt;h3&gt;
  
  
  6. Public endpoints have a rate limit
&lt;/h3&gt;

&lt;p&gt;What breaks: your login, sign-up, password reset and contact form accept unlimited requests. A script can try thousands of passwords on one account, create thousands of fake accounts, or send thousands of emails through your contact form, and your email provider bills you or blocks you.&lt;/p&gt;

&lt;p&gt;A rate limit is a bouncer with a counter. Five tries from the same place in a minute, fine. The sixth gets told to wait, with the status code 429, Too Many Requests.&lt;/p&gt;

&lt;p&gt;The test: try to log in twenty times in a row with a wrong password.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;checks/rate-limit.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BASE_URL&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s2"&gt;"http://localhost:3000"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;counts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${BASE}/api/login`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"content-type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"demo@example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"wrong-password"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;counts is an empty object that will count how many times each status came back. The loop sends twenty login attempts for &lt;a href="mailto:demo@example.com"&gt;demo@example.com&lt;/a&gt; with a wrong password, one after another. counts[res.status] ?? 0 means "the count so far, or zero if this status is new", plus one. At the end you see the tally.&lt;/p&gt;

&lt;p&gt;Point the address at whatever your sign-in form actually posts to; the network tab in the developer tools shows it when you submit the form once. Some auth libraries also expect extra fields or a CSRF token, so if every answer is the same error, check that your request looks like the one the form sends.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# no limit&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;'401'&lt;/span&gt;: 20 &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# with a limit of 5 per minute&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;'401'&lt;/span&gt;: 5, &lt;span class="s1"&gt;'429'&lt;/span&gt;: 15 &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Twenty 401s means twenty honest "wrong password" answers and no limit at all. Five 401s and fifteen 429s means the bouncer is working.&lt;/p&gt;

&lt;p&gt;Do it for every public endpoint that does real work: login, sign-up, password reset, contact, newsletter, anything that sends an email or costs money. &lt;a href="https://codefromscratch.org/blog/api-rate-limiting-nextjs?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Rate Limiting Your Next.js API&lt;/a&gt; shows how to build the limit, and why a counter kept in memory isn't enough when your app runs on several serverless instances at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Payments: a webhook must prove who sent it
&lt;/h2&gt;

&lt;h3&gt;
  
  
  7. A fake "payment succeeded" is rejected
&lt;/h3&gt;

&lt;p&gt;A webhook is a message another service sends to your app when something happens. Stripe calls your /api/webhooks/stripe address to say "this customer paid", and your app switches on the paid plan. Here's the catch: that address is public. Anyone on the internet can send a POST to it.&lt;/p&gt;

&lt;p&gt;So Stripe signs every message with a secret only you and Stripe know, and puts the signature in the Stripe-Signature header. Your code must check it before believing anything. Stripe's docs put it bluntly: &lt;a href="https://docs.stripe.com/webhooks/signature" rel="noopener noreferrer"&gt;without verification, an attacker could send fake webhook events to your endpoint&lt;/a&gt; to trigger things like fulfilling orders or granting access.&lt;/p&gt;

&lt;p&gt;The test: send your own webhook a payment that never happened.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;checks/fake-webhook.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BASE_URL&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s2"&gt;"http://localhost:3000"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fakeEvent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"evt_fake"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"checkout.session.completed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"cs_fake"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;customer_email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"demo@example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount_total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${BASE}/api/webhooks/stripe`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"content-type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"stripe-signature"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"t=1,v1=forged"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fakeEvent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"FAIL  the fake payment was accepted"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OK    rejected"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;fakeEvent has the shape of a real Stripe event: an id, a type that says a checkout was completed, and a data object with an email and an amount of 0. The request carries a Stripe-Signature header too, but the signature is made up. A handler that verifies signatures will see that v1=forged doesn't match and refuse. A handler that just reads the JSON will happily switch on the plan.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# handler that only parses the JSON&lt;/span&gt;
200 FAIL  the fake payment was accepted

&lt;span class="c"&gt;# handler that verifies the signature&lt;/span&gt;
400 OK    rejected
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you get a 200, stop and fix it before launch, because this is free premium access for anyone who reads this paragraph. &lt;a href="https://codefromscratch.org/blog/stripe-webhook-verification?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Stripe Webhooks: Verify the Signature or Lose Money&lt;/a&gt; walks through the fix, including the part that trips everyone up: the signature is computed over the raw body, so you must verify before anything parses or reformats it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure: when something goes wrong, you find out first
&lt;/h2&gt;

&lt;p&gt;Everything breaks at some point. A production app isn't one that never fails; it's one where failure is small, quiet for the user and loud for you.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Errors tell the user little and you a lot
&lt;/h3&gt;

&lt;p&gt;You already ran this test. Look back at the bad input output: "TypeError: body.plan.toUpperCase is not a function" went straight to the visitor. A stack trace tells an attacker your file names, your libraries and sometimes your database. It also tells a normal user nothing useful.&lt;/p&gt;

&lt;p&gt;The fix has two halves. The visitor gets a calm message and a way forward. You get the full error, with the details, in your logs. In the browser, error boundaries catch a crashed component so one broken widget doesn't blank the whole page; &lt;a href="https://codefromscratch.org/blog/error-boundaries-done-right?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;React Error Boundaries Done Right&lt;/a&gt; shows where to put them in the App Router.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. You can find yesterday's error in one minute
&lt;/h3&gt;

&lt;p&gt;The test is not a script, it's a stopwatch. Trigger the wrong type case from check 5 again. Now open your host's logs (on Vercel, the project's Logs tab) and find that exact error. Start the timer.&lt;/p&gt;

&lt;p&gt;If you find it in under a minute, with the route, the time and the message, you're fine. If you're scrolling through a wall of text, or the error isn't there at all because the code caught it and said nothing, fix that now. A user will write to you one day saying "it didn't work yesterday around lunch", and this is the moment you'll need it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codefromscratch.org/blog/structured-logging-nextjs?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Structured Logging in Next.js&lt;/a&gt; shows the small change that makes logs searchable: one JSON line per event, with a request id you can follow from start to end.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. You can roll back in two minutes, and you've tried it
&lt;/h3&gt;

&lt;p&gt;What breaks: you deploy on a Friday evening, the new version has a bug that blocks every login, and you don't know how to put the old version back. On Vercel there's a button for that, Instant Rollback. Read the &lt;a href="https://vercel.com/docs/instant-rollback" rel="noopener noreferrer"&gt;rollback docs&lt;/a&gt; for two details that matter: on the free Hobby plan you can roll back to the immediately previous deployment only, and environment variables are not rolled back with the code.&lt;/p&gt;

&lt;p&gt;The test: do it once on purpose, on a calm day. Deploy a tiny harmless change, roll it back, check the site, then undo the rollback. Time yourself. Under two minutes, and you know where the button is when your hands are shaking.&lt;/p&gt;

&lt;p&gt;One thing no button can roll back is your database. If the bad version changed the shape of your data, putting the old code back can make it worse. &lt;a href="https://codefromscratch.org/blog/rollback-without-feature-flags?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Rollback Strategies for Small Teams&lt;/a&gt; explains how to change a database so that the previous version of the code still works with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependencies: every package is real, needed and patched
&lt;/h2&gt;

&lt;h3&gt;
  
  
  11. No package the AI made up, and none with known holes
&lt;/h3&gt;

&lt;p&gt;What breaks: models sometimes suggest packages that don't exist. Researchers measured this in a paper at USENIX Security 2025 and found that &lt;a href="https://www.usenix.org/conference/usenixsecurity25/presentation/spracklen" rel="noopener noreferrer"&gt;the average share of hallucinated packages was at least 5.2% for commercial models and 21.7% for open-source models&lt;/a&gt;, with 205,474 unique made-up names in their tests. A made-up name is harmless while nobody owns it. The danger starts when someone registers that exact name with bad code inside, and your install pulls it in.&lt;/p&gt;

&lt;p&gt;The test: ask the npm registry about every package in your package.json.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;checks/check-packages.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;readFileSync&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:fs"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pkg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"package.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"utf8"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pkg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dependencies&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pkg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;devDependencies&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;DAY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`https://registry.npmjs.org/${name.replace("/", "%2F")}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`MISSING  ${name}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;created&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;DAY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${days &amp;lt; 90 ? "NEW    " : "ok     "}  ${name} (first published ${days} days ago)`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script reads package.json and merges dependencies and devDependencies into one list of names. For each name it asks registry.npmjs.org, the public npm registry, for that package's record. Scoped packages like &lt;code&gt;@types/node&lt;/code&gt; need the slash written as %2F in the address, which is what the replace does.&lt;/p&gt;

&lt;p&gt;A 404 means the package doesn't exist at all: MISSING. Otherwise the record has a time.created field, the date the package was first published, and the script turns it into days. Anything younger than 90 days gets the label NEW. New isn't bad by itself; new and unknown and suggested by an AI is worth a look. Open its page, check who publishes it, whether it has a real repository and real users.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ node checks/check-packages.mjs
ok       next &lt;span class="o"&gt;(&lt;/span&gt;first published 5602 days ago&lt;span class="o"&gt;)&lt;/span&gt;
ok       zod &lt;span class="o"&gt;(&lt;/span&gt;first published 2439 days ago&lt;span class="o"&gt;)&lt;/span&gt;
ok       @types/node &lt;span class="o"&gt;(&lt;/span&gt;first published 3830 days ago&lt;span class="o"&gt;)&lt;/span&gt;
MISSING  this-package-should-not-exist-cfs-xyz-123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then two more things, without a script. Run npm's built-in audit, which &lt;a href="https://docs.npmjs.com/cli/v11/commands/npm-audit" rel="noopener noreferrer"&gt;sends your dependency list to the registry and reports known vulnerabilities&lt;/a&gt;; with --omit=dev it looks only at what ships to production. And go through package.json line by line asking "do I use this?" AI tools add packages for one experiment and never remove them. Every package you don't need is code you didn't read, running with your permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tests: the three paths that hurt the most are guarded
&lt;/h2&gt;

&lt;h3&gt;
  
  
  12. Login, money and permissions have tests
&lt;/h3&gt;

&lt;p&gt;You don't need tests everywhere. You need them where a bug costs real money or exposes real people: who can sign in, what gets charged, and who can see what. Everything you just did by hand becomes a test that runs on every change, so a future "small fix" from you or from an AI can't quietly reopen the hole.&lt;/p&gt;

&lt;p&gt;Here's check 3 turned into a test with Node's built-in test runner, which the &lt;a href="https://nodejs.org/api/test.html" rel="noopener noreferrer"&gt;Node docs&lt;/a&gt; mark as stable. Nothing to install.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tests/access.test.mjs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:test"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;assert&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:assert/strict"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BASE_URL&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s2"&gt;"http://localhost:3000"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cookie&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;cookie&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Emily can read her own order"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${BASE}/api/orders/1001`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;EMILY_COOKIE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Emily cannot read James's order"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${BASE}/api/orders/1002`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;EMILY_COOKIE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"a signed-out visitor gets nothing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${BASE}/api/orders/1001`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;test comes from node:test and registers one test with a name and an async function. assert from node:assert/strict gives you assert.equal, which fails the test when two values differ. The as helper builds the fetch options: with a cookie it sends it, without one it sends no headers, so the same helper covers "signed in as Emily" and "signed out".&lt;/p&gt;

&lt;p&gt;Three tests, three rules in plain English. Emily can read her own order, so 200. Emily can't read James's order, so 404. Nobody signed out gets any order, so 401, which means "sign in first". Notice the first test. It's there so the second one can't pass by accident: if the route were simply broken for everybody, the 404 test would pass and lie to you.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# against the route as generated&lt;/span&gt;
$ node --test tests/
✔ Emily can &lt;span class="nb"&gt;read&lt;/span&gt; her own order
✖ Emily cannot &lt;span class="nb"&gt;read&lt;/span&gt; James&lt;span class="s1"&gt;'s order
  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  200 !== 404

# against the fixed route
$ node --test tests/
✔ Emily can read her own order
✔ Emily cannot read James'&lt;/span&gt;s order
✔ a signed-out visitor gets nothing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;node --test finds files ending in .test.mjs on its own. If your project already uses Vitest or Jest, write the same three tests there; the idea doesn't change. Add one test for the price (the server's price wins) and one for the webhook (an unsigned event is refused), and you've covered the three paths. &lt;a href="https://codefromscratch.org/blog/testing-react-applications-a-complete-strategy?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Testing React Applications&lt;/a&gt; covers the rest of a testing strategy, once these are in place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running the whole checklist in 30 minutes with an AI agent
&lt;/h2&gt;

&lt;p&gt;Here's the part people get backwards. They ask the AI "is my app secure?", get a confident "yes, with a few suggestions", and feel better. That's asking the cook whether the food is good.&lt;/p&gt;

&lt;p&gt;The split that works: the AI does the mechanical part, you do the judgment. It's the same way I work with an AI agent on any task. We talk the project through first, we make a plan, then we go step by step: I give the steps, the AI writes the code, I check it.&lt;/p&gt;

&lt;p&gt;For this checklist, the steps look like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ask the agent for an inventory, not an opinion: every route and server action, the HTTP method, whether it requires a login, and the exact line where it checks who owns the data. Ask for "none" where there's no such line.&lt;/li&gt;
&lt;li&gt;Read that list yourself. Every "none" on a route that takes an id is a candidate for check 3. This is the judgment part, and it's the part you can't hand over.&lt;/li&gt;
&lt;li&gt;Ask the agent for a second list: every environment variable, where it's read, and whether that file can run in the browser. Compare it with what bundle-leak.mjs found.&lt;/li&gt;
&lt;li&gt;Ask it to write the tests from check 12 for your real routes, then run them yourself and read the failures. A test you didn't watch fail once is a test you can't fully trust.&lt;/li&gt;
&lt;li&gt;Run the scripts from this article in order. Write every FAIL into one list. Fix the list one item at a time, rerunning the matching script after each fix.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thirty minutes is enough for the inventory and the scripts on a small app. Fixing what you find takes longer, and that's fine. The point of the first session is to know, not to be done.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For advanced readers: put these scripts in CI. The ones that set an exit code (two-accounts.mjs, the node:test file) can fail a pull request; run them against a preview deployment with dedicated test accounts and seeded data, never against production users. Treat the inventory from the agent as a document you regenerate on every bigger change, because new routes are where new holes appear.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  When vibe coding is completely fine
&lt;/h2&gt;

&lt;p&gt;I don't want you to walk away thinking every AI-built thing needs a security audit. It doesn't.&lt;/p&gt;

&lt;p&gt;A prototype you show to three friends is fine. An internal tool that only you use, on your own machine, is fine. A weekend experiment to learn how something works is great, actually; that's one of the best uses of these tools. Vibe code all of that freely.&lt;/p&gt;

&lt;p&gt;The line is simple. The moment your app holds other people's data, takes money, sends email in your name, or does anything you can't take back, it's not a prototype anymore. That's when the checklist stops being optional. Before that line, speed wins. After it, this list wins.&lt;/p&gt;

&lt;h2&gt;
  
  
  So that's all it is
&lt;/h2&gt;

&lt;p&gt;Look at the twelve checks again and you'll see they're really one idea, repeated: don't trust anything that comes from outside the server until you've checked it. The cookie says who is asking; check whose data it is. The body says the price; ignore it and use yours. The webhook says someone paid; check the signature. The package name in a suggestion; check it exists. The key in the code; make sure it never leaves.&lt;/p&gt;

&lt;p&gt;Generated code mostly trusts. Your job is to add the places where it shouldn't. Once you see that, you stop needing a checklist for every new feature. You just ask, for each new route, "what's coming from outside, and where do I check it?"&lt;/p&gt;

&lt;h2&gt;
  
  
  What to be careful about, and the Plan B
&lt;/h2&gt;

&lt;p&gt;These scripts are a floor, not a ceiling. Passing all twelve means you've closed the most common holes, not every hole. They don't test things like cross-site scripting, file uploads, or the security of the services you depend on. Don't write "secure" on your landing page because a script printed OK.&lt;/p&gt;

&lt;p&gt;Another trap: testing with one account. Every access bug hides when you're signed in as the owner. Two accounts minimum, always, and ideally a third with an admin role so you can check that ordinary users can't reach admin routes.&lt;/p&gt;

&lt;p&gt;And keep the outputs. A FAIL you fixed today can come back with the next generated change. That's why check 12 exists: the tests remember so you don't have to.&lt;/p&gt;

&lt;p&gt;Now the Plan B, because a good programmer thinks a few steps ahead: scaling, security, reliability, and always a backup plan. Here's mine for this situation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you find a hole in an app that's already live, close the door first and investigate second. Roll back if the previous version was safe, or turn the route off until it's fixed.&lt;/li&gt;
&lt;li&gt;If a secret leaked, rotate it now, then move it to an environment variable, then worry about git history.&lt;/li&gt;
&lt;li&gt;If you take payments and you're not confident in your webhook and pricing code, use a hosted checkout page from your payment provider, where the price is set on their side, until you are.&lt;/li&gt;
&lt;li&gt;If the checklist turns up more than you can fix alone, don't launch to the public yet. Invite a small group you know, fix things in order of damage, and ask someone more experienced to look at the access checks. Asking for help isn't weakness; plenty of people in real companies don't know everything either.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your Plan B is "hope nobody notices", that's not a Plan B.&lt;/p&gt;

&lt;h2&gt;
  
  
  The checklist, on one screen
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;1. No secret in the code. Test: find-secrets.mjs; only .env.local may match.&lt;/li&gt;
&lt;li&gt;2. No secret in the browser. Test: build, then bundle-leak.mjs finds 0.&lt;/li&gt;
&lt;li&gt;3. Every request checks whose data it is. Test: two-accounts.mjs refuses, on every route with an id.&lt;/li&gt;
&lt;li&gt;4. The server decides prices and roles. Test: bad-input.mjs, a price of 1 and role admin are ignored.&lt;/li&gt;
&lt;li&gt;5. Bad input gets a 400, not a crash. Test: bad-input.mjs, wrong type and non-JSON give 400.&lt;/li&gt;
&lt;li&gt;6. Public endpoints have a rate limit. Test: rate-limit.mjs shows 429s.&lt;/li&gt;
&lt;li&gt;7. Webhooks verify signatures. Test: fake-webhook.mjs is rejected.&lt;/li&gt;
&lt;li&gt;8. Errors don't leak internals. Test: no LEAKS INTERNALS in the bad-input output.&lt;/li&gt;
&lt;li&gt;9. You can find an error in a minute. Test: a stopwatch and your host's logs.&lt;/li&gt;
&lt;li&gt;10. You can roll back in two minutes. Test: roll back once on purpose.&lt;/li&gt;
&lt;li&gt;11. Every package is real, needed and patched. Test: check-packages.mjs, npm audit --omit=dev, and a read of package.json.&lt;/li&gt;
&lt;li&gt;12. Login, money and permissions have tests. Test: node --test passes, and you watched it fail first.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to learn next
&lt;/h2&gt;

&lt;p&gt;Start with check 3, the two-accounts test, on your own app tonight. It's the one most likely to find something real. Then read &lt;a href="https://codefromscratch.org/blog/production-grade-code-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Production-Grade Code&lt;/a&gt;, which is the other side of this article: not how to inspect an app, but how to write it so these checks pass the first time.&lt;/p&gt;

&lt;p&gt;If you're early in your journey and all of this felt like a lot, that's normal. &lt;a href="https://codefromscratch.org/blog/learn-web-development-from-scratch-with-ai?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Learning Web Development From Scratch With AI&lt;/a&gt; is about which of these concepts to learn first, so the AI becomes a fast pair of hands instead of the only one who knows how your app works.&lt;/p&gt;

&lt;p&gt;Every check here is something you can understand, run and fix, one at a time. You can do this and you have to. If you weren't capable I wouldn't spend my time on you. Just don't give up and you'll always have me on your side.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/vibe-coding-production-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=vibe-coding-production-checklist"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>nextjs</category>
      <category>node</category>
    </item>
    <item>
      <title>Build a Pricing Table From Scratch: The CSS Tricks Behind It</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Fri, 13 Nov 2026 18:20:15 +0000</pubDate>
      <link>https://dev.to/codefromscratch/build-a-pricing-table-from-scratch-the-css-tricks-behind-it-2noe</link>
      <guid>https://dev.to/codefromscratch/build-a-pricing-table-from-scratch-the-css-tricks-behind-it-2noe</guid>
      <description>&lt;p&gt;Every app that sells something has the same page: three cards side by side, a price in big numbers, a list of what you get, a button, and one card in the middle that says "Most popular". You've seen it a hundred times. Today we build that pattern from scratch, with our own plans and our own colours, and I'll show you the four small CSS tricks that make it look finished instead of almost right.&lt;/p&gt;

&lt;p&gt;Here's the short answer first. A pricing table is a CSS grid of cards that wraps on its own with repeat(auto-fit, minmax(...)). Each card is a flex column, and the button gets margin-top: auto so every button sits on the same line. The favourite plan gets a border and a badge, not a zoom. Prices use tabular numbers and live in cents. That's the whole thing.&lt;/p&gt;

&lt;p&gt;If you're a beginner, read it top to bottom and click every live demo, because seeing the difference is worth more than my words. If you already write CSS every day, jump to the section about the highlighted card and then to the one about subgrid. Those are the two places where people who know the basics still get it wrong. The part about prices, money and the Plan B is for anyone who has ever had to put a real price on a real page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why we rebuild a design everyone has already seen
&lt;/h2&gt;

&lt;p&gt;This article is part of a series I call Concepts in practice. The idea is simple. Instead of learning CSS properties one by one from a list, we take a piece of a website you already know from real life, rebuild it, and look at the tricks behind it. You learn faster when you already know what the finished thing should look like.&lt;/p&gt;

&lt;p&gt;I'll be honest about why this matters to me. When I started, I built everything from my head. No plan, no sketch, no visual reference. I just kept changing things until I liked how it looked. That works right up until it doesn't, and with a pricing table it stops working very fast, because the page has to look right with three different amounts of text, on a phone and on a big screen, and with a price that changes when someone clicks a switch.&lt;/p&gt;

&lt;p&gt;The good news is that the people who design the big websites have already solved most of these problems. Look at enough pricing pages and you'll notice they all use the same few moves. That's what we'll steal today: the moves, not the look.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Rebuild the pattern, never the brand. The layout idea of a pricing table belongs to nobody. A company's logo, its exact wording, its illustrations and its colours do belong to someone. In this article every plan name, price and colour is made up. Do the same when you practise, and especially before anything you build goes on a public page.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why your first pricing table always looks a little off
&lt;/h2&gt;

&lt;p&gt;Let's look at the problem before we fix it. Below is the version almost everyone writes first. Three cards in a row with display: flex, and the middle card made bigger with transform: scale(1.08) so it stands out. Press "Apply the fixes" to switch to the fixed version and back again.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; Pricing cards: the first attempt and the fixed version. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/pricing-table-from-scratch-css?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Look at the first version closely and you'll see three things that feel wrong, even if you can't name them yet.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The buttons are at different heights. Each button sits right under its own list, and the lists have two, four and three items. Your eye expects them on one line, because they do the same job.&lt;/li&gt;
&lt;li&gt;The middle card is zoomed, but the cards next to it don't know that. The gap on each side gets smaller and the card pokes out above and below the row. With a slightly bigger zoom or a smaller gap, it would cover its neighbours.&lt;/li&gt;
&lt;li&gt;On a phone the row never breaks. Flexbox keeps all three cards on one line, so each one gets about a third of a small screen and the text gets squashed. Open the demo in full screen on your phone and you'll see it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why does this happen? Because each of those properties does exactly what it says, and nothing more. Flexbox with no wrapping puts things in one row. A card is only as tall as its content tells it to be, unless something stretches it. And a transform, by design, is a visual effect that the layout ignores. The W3C specification says it in so many words. None of this is a bug. It's us asking for the wrong thing.&lt;/p&gt;

&lt;p&gt;The transform part surprises most people, so here's the exact line from &lt;a href="https://www.w3.org/TR/css-transforms-1/" rel="noopener noreferrer"&gt;the CSS Transforms specification&lt;/a&gt;: "the transform property does not affect the flow of the content surrounding the transformed element." In plain words, the browser first lays out the page as if the zoom didn't exist, and only then paints the card bigger on top of that layout.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with the markup, not the look
&lt;/h2&gt;

&lt;p&gt;Before any CSS, decide what each piece of the card is. This sounds boring and it's the step I used to skip. It's also what makes the page readable for a screen reader and for Google, and it makes the CSS shorter, because you style real elements instead of a pile of divs.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pricing.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;article&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"card featured"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"badge"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Most popular&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;Pro&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"desc"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;For one person who ships every week.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"price"&lt;/span&gt; &lt;span class="na"&gt;data-monthly&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"1200"&lt;/span&gt; &lt;span class="na"&gt;data-yearly&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"12000"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"amount"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;$12&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"per"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;/ month&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"billed"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Billed every month&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"list"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Unlimited projects&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Custom domain&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"cta"&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/signup?plan=pro"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Choose Pro&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go through it line by line.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;article: each plan is a self-contained thing that would make sense on its own, which is what article means in HTML. A div would work visually, but it tells nobody anything.&lt;/li&gt;
&lt;li&gt;p class="badge": the "Most popular" label is just a short paragraph. Only the featured card has it. We'll lift it onto the card's top border later with CSS, but in the HTML it's ordinary text, so it's read out like ordinary text.&lt;/li&gt;
&lt;li&gt;h3: the plan name is a heading. Someone using a screen reader can jump from heading to heading and hear Starter, Pro, Team. It's h3 because the section around the table has its own h2, like "Pick a plan". Headings go in order; don't pick a level because of its size.&lt;/li&gt;
&lt;li&gt;p class="price" with two data attributes: data-monthly and data-yearly hold the price in cents, as plain numbers. The text inside, $12, is what the visitor sees when the page loads, even if JavaScript never runs. We'll come back to why cents.&lt;/li&gt;
&lt;li&gt;span class="amount" and span class="per": the number and the "/ month" are separate, because they look different. The number is big, the "/ month" is small and grey.&lt;/li&gt;
&lt;li&gt;ul role="list": the features are a real list. The role="list" looks redundant, and I'll explain later why it's there.&lt;/li&gt;
&lt;li&gt;a class="cta": the button is a link, not a button element. It takes you to another page, the sign-up page with the plan in the address. That's a link's job. A button element is for things that happen on the same page, like the monthly and yearly switch.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Quick rule for links and buttons: if it goes somewhere, it's a link. If it does something here, it's a button. Get this right and keyboard users, screen readers and the browser's back button all behave the way people expect, without extra code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Trick one: a grid that wraps itself
&lt;/h2&gt;

&lt;p&gt;Now the layout. We want three cards side by side when there's room, two when there's a bit less, and one on a phone. The old way was three media queries. The modern way is one line. If grid itself is new to you, &lt;a href="https://codefromscratch.org/blog/css-grid-layout-the-complete-visual-guide?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;my visual guide to CSS Grid&lt;/a&gt; covers the basics, and &lt;a href="https://codefromscratch.org/blog/css-flexbox-vs-grid-real-layouts?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;Flexbox vs Grid on real layouts&lt;/a&gt; explains why this job belongs to grid and not to flexbox.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pricing.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.plans&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto-fit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13rem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1fr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That middle line looks scary, so let's read it from the inside out.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;13rem is the narrowest a card is allowed to be. With the default font size that's 208 pixels. Below that, the text inside a card starts to feel cramped.&lt;/li&gt;
&lt;li&gt;min(100%, 13rem) picks the smaller of the two. On a normal screen that's 13rem. On a very narrow phone, where 13rem would be wider than the screen, it becomes 100%, so the card never sticks out sideways. Without this little min(), a 13rem card on a tiny screen causes a horizontal scrollbar.&lt;/li&gt;
&lt;li&gt;minmax(that, 1fr) means: each column is at least that wide, and at most one equal share of the free space. So the cards grow to fill the row, all the same width.&lt;/li&gt;
&lt;li&gt;repeat(auto-fit, ...) tells the browser: you count how many columns fit. Three fit on a laptop, two on a tablet, one on a phone. You never write a breakpoint.&lt;/li&gt;
&lt;li&gt;gap: 1.25rem is the space between cards, both between columns and between rows when they wrap. No margins on the cards, so nothing doubles up at the edges.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of a long bench where people only sit if they have at least shoulder width. When the bench is long, three people sit and spread out a bit. When it's shorter, only two fit, and the third person starts a new row behind them. Nobody has to tell them where to sit; the rule does it.&lt;/p&gt;

&lt;p&gt;You'll also see auto-fill instead of auto-fit, and the difference matters with only three cards. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat" rel="noopener noreferrer"&gt;MDN puts it&lt;/a&gt; like this: auto-fit "behaves as auto-fill, except that after placing grid items, any empty repeated tracks are collapsed." On a very wide screen, auto-fill keeps empty columns as ghosts, so your three cards stay narrow and huddle on the left. auto-fit throws the empty columns away, and the three cards stretch across the row. For a pricing table you want auto-fit. You'll also want a max-width on the section, so the cards don't stretch into pancakes on a huge monitor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trick two: push every button to the same line
&lt;/h2&gt;

&lt;p&gt;Grid already gives us one gift for free. By default, every card in a grid row is stretched to the height of the tallest one. So the white boxes are already the same height. The problem is what's inside them: the button still sits right under the list. We need the button to fall to the bottom of its card.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pricing.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.cta&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;display: flex with flex-direction: column turns the inside of each card into a vertical stack. Badge, name, description, price, list, button, one under the other, like before.&lt;/li&gt;
&lt;li&gt;margin-top: auto on the button is the trick. In a flex container, an auto margin takes all the free space it can. So all the empty space in the card ends up above the button, and the button lands at the bottom.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Picture a compressed spring placed right above the button. The spring pushes out until it hits the content above it, and whatever space is left, it fills. Every card has its own spring, so every button ends up at the bottom of its card, and because grid made the cards the same height, the buttons line up. MDN's page on &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container" rel="noopener noreferrer"&gt;aligning items in a flex container&lt;/a&gt; explains it with a row instead of a column: the auto margin "consumes all the space it can in its axis". Same idea, turned 90 degrees.&lt;/p&gt;

&lt;p&gt;What breaks if you remove it? Take away margin-top: auto and the buttons jump back under their lists. Take away display: flex on the card and the auto margin does nothing, because in normal block layout an auto top margin is just zero. You need both lines.&lt;/p&gt;

&lt;p&gt;You'll find people doing this with a fixed height on every card, something like height: 420px. Please don't. The day someone adds a fifth feature to the Pro plan, or a visitor makes the text bigger in their browser, the text spills out of the card. The spring adapts. A fixed height doesn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trick three: highlight the favourite without zooming it
&lt;/h2&gt;

&lt;p&gt;Every pricing page wants one plan to stand out. The zoom we saw in the first demo is the most common way, and now you know why it fights the layout. Here's the version that works with the layout instead.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pricing.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.featured&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2px&lt;/span&gt; &lt;span class="n"&gt;solid&lt;/span&gt; &lt;span class="mh"&gt;#0b6e4f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.badge&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;-50&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;-50&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;white-space&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nowrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;.featured gets a thicker border in our accent colour. That alone makes it stand out, and it takes up real space, so the layout knows about it. The cards next to it make room.&lt;/li&gt;
&lt;li&gt;position: relative on the card doesn't move the card at all. It only says: anything inside me with position: absolute should measure from my corners, not from the page.&lt;/li&gt;
&lt;li&gt;position: absolute on the badge takes it out of the stack, so it doesn't push the plan name down. Then top: 0 and left: 50% put the badge's top-left corner at the middle of the card's top edge.&lt;/li&gt;
&lt;li&gt;translate: -50% -50% moves the badge back by half of its own width and half of its own height. Now its centre sits exactly on the card's border, half outside and half inside. That's the classic "label sitting on the edge" look.&lt;/li&gt;
&lt;li&gt;white-space: nowrap keeps "Most popular" on one line, even when the card gets narrow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wait, didn't I just say transforms are bad here? Look closely: translate on the badge is fine, because we want the badge to float over the border, and it's out of the layout anyway. The problem was never transforms. The problem was using a transform on something that the rest of the layout should make room for.&lt;/p&gt;

&lt;p&gt;If you want the favourite to look bigger as well, give it more padding at the top and bottom, or a slightly larger price. Those are real sizes, so the grid adapts. Just remember that grid stretches every card in the row, so a taller featured card makes the others taller too. That's usually fine, and it keeps the buttons in line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trick four: prices that don't wobble
&lt;/h2&gt;

&lt;p&gt;This one is small and almost nobody notices it consciously, which is the point. When you switch from monthly to yearly, the numbers change. In most fonts, the digit 1 is narrower than the digit 0, so $12 and $10 are different widths and the price jumps sideways a little when it changes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pricing.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.price&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;2.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;700&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.amount&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;font-variant-numeric&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tabular-nums&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.per&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.9rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#52606d&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;.price makes the number big and bold, and line-height: 1 stops a big font from adding a lot of empty space above and below the line.&lt;/li&gt;
&lt;li&gt;.amount uses font-variant-numeric: tabular-nums. That asks the font for its table digits, which are all the same width. Same idea as numbers in a bank statement lining up in a column.&lt;/li&gt;
&lt;li&gt;.per makes "/ month" small, normal weight and grey, so the eye reads the number first and the period second.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric" rel="noopener noreferrer"&gt;MDN describes tabular-nums&lt;/a&gt; as the set of figures "where numbers are all of the same size, allowing them to be easily aligned like in tables." It depends on the font having those figures; the system fonts on the common operating systems do, and most good web fonts do. If a font doesn't have them, nothing breaks, you just get the normal digits.&lt;/p&gt;

&lt;h2&gt;
  
  
  The monthly and yearly switch is a radio group in disguise
&lt;/h2&gt;

&lt;p&gt;Most pricing pages have a pill-shaped switch on top: Monthly or Yearly. It looks like a custom widget, and a lot of people build it from divs and click handlers. But think about what it really is. You pick one option out of two, and exactly one is always selected. HTML has had an element for that since forever: radio buttons.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pricing.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;fieldset&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"billing"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;legend&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"visually-hidden"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Billing period&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"monthly"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"billing"&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"monthly"&lt;/span&gt; &lt;span class="na"&gt;checked&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"monthly"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Monthly&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yearly"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"billing"&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yearly"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yearly"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Yearly, 2 months free&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;fieldset groups the two options, and legend gives the group a name, "Billing period". A screen reader announces it when you enter the group. We hide the legend visually because the pills explain themselves to sighted visitors, but we don't remove it.&lt;/li&gt;
&lt;li&gt;Both inputs share name="billing", and that's what makes them one group: choosing one automatically un-chooses the other. You get that for free.&lt;/li&gt;
&lt;li&gt;checked on the monthly input makes it the starting choice, and it matches the prices written in the HTML.&lt;/li&gt;
&lt;li&gt;Each label is tied to its input with for and id. Clicking the label selects the radio, so the whole pill is clickable. The arrow keys move between the two options, again for free.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;pricing.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.billing&lt;/span&gt; &lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.billing&lt;/span&gt; &lt;span class="nt"&gt;label&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5rem&lt;/span&gt; &lt;span class="mi"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1px&lt;/span&gt; &lt;span class="n"&gt;solid&lt;/span&gt; &lt;span class="mh"&gt;#1f2933&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;999px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.billing&lt;/span&gt; &lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;checked&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nt"&gt;label&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#1f2933&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.billing&lt;/span&gt; &lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;focus-visible&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nt"&gt;label&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;outline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3px&lt;/span&gt; &lt;span class="n"&gt;solid&lt;/span&gt; &lt;span class="mh"&gt;#0b6e4f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;outline-offset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The first line hides the round radio circles, but not with display: none. That's important. display: none would remove the inputs completely, and the keyboard couldn't reach them anymore. opacity: 0 and a 1-pixel size keep them in the page, just invisible.&lt;/li&gt;
&lt;li&gt;The labels become the pills: some padding, a border, and a border-radius so big that the ends are fully round.&lt;/li&gt;
&lt;li&gt;input:checked + label means: the label that comes right after a checked input. That's why each label sits directly after its input in the HTML. The selected pill gets the dark background.&lt;/li&gt;
&lt;li&gt;input:focus-visible + label draws a clear outline on the pill when someone reaches it with the keyboard. Since the real input is invisible, the focus ring has to show on the label, otherwise a keyboard user can't see where they are.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you'd rather build it with two buttons, that's fine too, but then you need &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-pressed" rel="noopener noreferrer"&gt;aria-pressed&lt;/a&gt; on each button and you have to keep exactly one pressed yourself. The first demo above uses aria-pressed on its single "Apply the fixes" button, which is the right tool for one on/off switch. For one choice out of two, the radio group does that work for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prices live in cents, and the page only displays them
&lt;/h2&gt;

&lt;p&gt;Now the JavaScript. It has one job: when the switch changes, show the right numbers. Before the code, one rule that will save you real trouble one day. Never do arithmetic with prices as decimals.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;money-check.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// 0.30000000000000004&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;119.99&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// 9.999166666666666&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I ran both lines under Node 26, and that's the real output. Computers store most decimal fractions as tiny approximations, so sums and divisions of dollars drift. That's why the HTML stores 1200 instead of 12.00. Whole cents are whole numbers, and whole numbers stay exact. We only turn them into dollars at the very last moment, when we print them.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pricing.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;money&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NumberFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"en-US"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"currency"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;currency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"USD"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;minimumFractionDigits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;maximumFractionDigits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;showPrices&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;period&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".price"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;period&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cents&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;perMonth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;period&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"yearly"&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;cents&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cents&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".amount"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;money&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;perMonth&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nextElementSibling&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
      &lt;span class="n"&gt;period&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"yearly"&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="sb"&gt;`${money.format(cents / 100)} billed once a year`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Billed every month"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".billing"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"change"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;showPrices&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#status"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`Showing ${event.target.value} prices`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Line by line, because this is where beginners usually start copying without reading.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;new Intl.NumberFormat("en-US", {...}) creates a formatter once. Give it a number, it gives you back a properly written price, with the dollar sign in the right place for that language. We create it once at the top instead of inside the loop, because it never changes.&lt;/li&gt;
&lt;li&gt;minimumFractionDigits: 0 and maximumFractionDigits: 0 say: no cents after the point. Our prices are whole dollars, so $10 looks cleaner than $10.00. Set both. Dollars come with default digit settings, and MDN warns that these defaults can clash with a value you set yourself and throw a RangeError, even if you only set one of the two.&lt;/li&gt;
&lt;li&gt;showPrices(period) receives "monthly" or "yearly", the value of the radio that was picked.&lt;/li&gt;
&lt;li&gt;document.querySelectorAll(".price") finds every price paragraph, and the for...of loop visits them one by one. Same pattern as rendering a list of cards: one piece of code, many items.&lt;/li&gt;
&lt;li&gt;price.dataset[period] reads data-monthly or data-yearly, depending on the period. dataset gives you every data- attribute of an element, and they always come back as text, so Number() turns "1200" into 1200.&lt;/li&gt;
&lt;li&gt;if (cents === 0) continue skips the free plan. Its text, "$0" and "Free forever", is already correct in the HTML for both periods, so we leave it alone.&lt;/li&gt;
&lt;li&gt;perMonth: for yearly billing we show the monthly equivalent, because that's the number people compare. 12000 cents a year divided by 12 is 1000 cents a month.&lt;/li&gt;
&lt;li&gt;money.format(perMonth / 100) turns cents into dollars only now, at the moment of printing, and writes the result into the .amount span with textContent. textContent sets plain text, never HTML, so nothing in there can turn into markup.&lt;/li&gt;
&lt;li&gt;price.nextElementSibling is the paragraph right after the price, the "billed" line. It changes to "$120 billed once a year" or back to "Billed every month", so nobody is surprised at checkout by a bigger number than the one they saw.&lt;/li&gt;
&lt;li&gt;The change listener sits on the fieldset, not on each radio. A change event from either radio bubbles up to the fieldset, so one listener covers both. event.target is the radio that was just picked.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every option of the formatter, including that warning about digit defaults, is on &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat" rel="noopener noreferrer"&gt;MDN's Intl.NumberFormat page&lt;/a&gt;. Keep it open the first few times you format money.&lt;/p&gt;

&lt;p&gt;If the loop over every .price feels familiar, it should. It's the same idea as &lt;a href="https://codefromscratch.org/blog/render-lists-without-repeating-code?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;rendering many cards without repeating code&lt;/a&gt;: one function, a list of items, and the data decides what each one shows. In a real project you'd go one step further and build the three cards from an array of plans too.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Rounding hides cents. With maximumFractionDigits: 0, a yearly price of 9900 cents shows as $8 a month, because 825 cents gets rounded. I ran it: the zero-decimals formatter prints $8, the normal one prints $8.25. Pick prices that divide evenly by 12, or show cents. Either way, the number on the page is only a display. The amount the customer actually pays must come from your server or your payment provider, never from a number the browser sent back.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  One quiet line for screen reader users
&lt;/h3&gt;

&lt;p&gt;The last line of the listener writes "Showing yearly prices" into a paragraph with aria-live="polite". That paragraph is visually hidden. When its text changes, a screen reader reads it out after it finishes what it's saying. Without it, a blind visitor presses the switch and hears nothing, while every price on the page has changed. We announce one short sentence instead of reading all three prices, because hearing three numbers at once is noise.&lt;/p&gt;

&lt;p&gt;Here is everything together: the markup, the grid, the spring, the badge, the switch and the script. Switch to Yearly and watch the Pro and Team prices change while their width stays the same. Then press Tab to walk through the page with the keyboard.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; Finished pricing table with a monthly and yearly switch. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/pricing-table-from-scratch-css?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  For the advanced reader: line up every row with subgrid
&lt;/h2&gt;

&lt;p&gt;Our buttons line up, but look at the lists. If one plan has a longer description, its list starts lower than the lists next to it, and so does its price. On a pricing page people compare across the row, Starter's price next to Pro's price, so rows that don't line up make comparing harder. The demo below has one long description on purpose. Press "Use subgrid" and watch the prices and lists snap into line.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; Lining up rows across cards with subgrid. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/pricing-table-from-scratch-css?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;pricing.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.plans&lt;/span&gt; &lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;grid-row&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;subgrid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;display: grid turns the card into a grid instead of a flex column.&lt;/li&gt;
&lt;li&gt;grid-row: span 5 makes each card occupy five rows of the outer grid, one row for each of its five children: name, description, price, list and button.&lt;/li&gt;
&lt;li&gt;grid-template-rows: subgrid is the key line. Instead of having its own rows, the card borrows the five rows of the outer grid. Since all three cards share the same five rows, each row is as tall as the tallest piece in it, across all cards. The long description makes row two taller for everyone, and every price lands on the same line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This used to be impossible without JavaScript measuring heights. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout/Subgrid" rel="noopener noreferrer"&gt;MDN marks subgrid&lt;/a&gt; as widely available and says it has worked across browsers since September 2023. Two things to watch. First, the number in span 5 must match the number of children in the card; if one plan has a badge as a sixth child, either take the badge out of the flow with position: absolute like we did, or count it. Second, the subgrid inherits the outer grid's gap between its rows, so the spacing inside the card is the same as the spacing between cards unless you set your own row-gap. In our demo that's fine. In a real design you may want to tune it.&lt;/p&gt;

&lt;p&gt;Is it overkill for a beginner? Yes, a bit. The flex version with the auto margin is perfectly fine for most pages. Reach for subgrid when the rows really need to line up, like a pricing table with long feature lists that people read across.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checkmarks that a screen reader still reads as a list
&lt;/h2&gt;

&lt;p&gt;Feature lists on pricing pages almost never show bullets. They show checkmarks. The usual move is list-style: none and a little icon. Here's a version that draws the check with plain CSS, no image, no icon font.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pricing.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="nt"&gt;ul&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;list-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;padding-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.card&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nt"&gt;before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.3rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.2em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.4rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.75rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;solid&lt;/span&gt; &lt;span class="mh"&gt;#0b6e4f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;2px&lt;/span&gt; &lt;span class="mi"&gt;2px&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;45deg&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;list-style: none removes the bullets, and padding: 0 removes the space the browser kept for them.&lt;/li&gt;
&lt;li&gt;Each li gets position: relative, so the checkmark can be placed against its own corner, and padding-left makes room for it.&lt;/li&gt;
&lt;li&gt;::before creates an extra, empty box in front of the text. content: "" is required; without content, the box doesn't exist at all.&lt;/li&gt;
&lt;li&gt;The box is narrow and tall, with only a right and a bottom border. That's an L shape. rotate: 45deg turns the L into a check. It's the same trick as drawing a tick with two strokes of a pen.&lt;/li&gt;
&lt;li&gt;Because content is empty, there's no character for a screen reader to read out. A checkmark character in content would be read aloud in some screen readers, on every single line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the role="list" from earlier. Safari with VoiceOver stops treating a list as a list when CSS removes its bullets. Scott O'Hara has &lt;a href="https://www.scottohara.me/blog/2019/01/12/lists-and-safari.html" rel="noopener noreferrer"&gt;written up this behaviour&lt;/a&gt;, including that WebKit does it on purpose. Adding role="list" to the ul puts the list back for that combination, and it changes nothing anywhere else. On a pricing table, "list, 4 items" is useful to hear, because it tells you how much a plan includes before you listen to all of it.&lt;/p&gt;

&lt;p&gt;One more thing about colour. I checked our colours with the standard WCAG contrast formula: white text on the green #0b6e4f comes out at 6.25 to 1, and the grey #52606d on white at 6.46 to 1. Both pass the 4.5 to 1 that normal text needs. Pricing pages love pale grey for the small print, and the small print is exactly the text people need to read.&lt;/p&gt;

&lt;h2&gt;
  
  
  So that's all a pricing table is
&lt;/h2&gt;

&lt;p&gt;Look back at what we built. A grid that decides on its own how many cards fit in a row. Cards that are flex columns, with a spring above the button. One card with a thicker border and a label sitting on its edge. Numbers that keep their width. A switch that is really two radio buttons, and ten lines of JavaScript that read cents from the HTML and print dollars.&lt;/p&gt;

&lt;p&gt;That's it. No framework, no library, nothing you couldn't type in a plain HTML file today. Every pricing page you admire is some version of these moves, plus good colours and good words. When you can see the moves, you stop seeing a design you could never make, and start seeing a few decisions you can make yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this goes wrong, and the Plan B
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The zoomed card. If you inherit a design with transform: scale on the featured plan, swap it for a border and extra padding. If the designer insists on the bigger look, give the featured card real extra padding so the layout makes room, rather than a zoom that the layout ignores.&lt;/li&gt;
&lt;li&gt;Fixed heights. Any height: 400px on a card breaks the day the text changes, or the day a visitor zooms their browser to 200%. Let content decide the height; use the auto margin or subgrid to line things up.&lt;/li&gt;
&lt;li&gt;Prices that exist only in JavaScript. If the cards are empty until a script fills them, a visitor on a slow connection sees blank boxes, and a search engine may see no prices at all. Write the default prices in the HTML and let JavaScript only change them.&lt;/li&gt;
&lt;li&gt;Trusting the page's price. The price on the page is a label. If your checkout takes the amount from the browser, someone will send a smaller one. The server looks up the plan and its price itself. This is the same rule as checking a login form twice, once in the browser for comfort and once on the server for real.&lt;/li&gt;
&lt;li&gt;Hiding the yearly total. Showing $10 a month without saying it's $120 paid at once is how people end up feeling tricked at checkout. The "billed" line costs one sentence and buys trust.&lt;/li&gt;
&lt;li&gt;Too many plans. Three columns fit the layout and the head. If you need five, the grid still works, but ask whether a visitor can really compare five things at once. That's a product question, not a CSS one, and it's worth asking.&lt;/li&gt;
&lt;li&gt;Copying a real company's page. Rebuilding the pattern to learn is fine. Shipping their logo, their wording, their illustrations or their exact colour scheme is not, and it also makes your product look like a copy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The "check twice" idea is the core of &lt;a href="https://codefromscratch.org/blog/login-form-validation-client-and-server?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;why you validate a login form on the client and the server&lt;/a&gt;, and when you get to real payments, &lt;a href="https://codefromscratch.org/blog/stripe-nextjs-setup?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;the Stripe setup guide for Next.js&lt;/a&gt; shows where the real price comes from.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If an AI assistant wrote your pricing table, check exactly the things in this article. Is the favourite card zoomed with a transform? Are there fixed heights? Is the switch a pile of divs that the keyboard can't reach? Are prices calculated with decimals? I use AI for a lot of my work, and I check what it writes as far as I can, because it can make these mistakes without meaning to. A pricing table is a good place to practise that kind of review, because every mistake is visible.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And for motion: the finished demo lifts a card by 4 pixels when you hover it, but only inside &lt;code&gt;@media&lt;/code&gt; (prefers-reduced-motion: no-preference). People who asked their system for less motion get a still page. It's one wrapper around two lines, and it's the polite default for every hover effect you add.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to build next
&lt;/h2&gt;

&lt;p&gt;Take this exact pattern and make it yours without looking at the demo code. Change it to four plans, add a long description to one of them, and check it on your phone. Then pick another piece of a website you use every day, a sign-up form, a product card, a page header that stays on top while you scroll, and rebuild it with your own text and colours. Write down the tricks you had to look up. That list is how you learn CSS for real. If you're starting from zero, &lt;a href="https://codefromscratch.org/blog/html-css-beginners-build-first-web-page?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;build your first web page with HTML and CSS&lt;/a&gt; first, and if you want the bigger picture of where this fits, &lt;a href="https://codefromscratch.org/blog/what-is-web-development-beginners-guide?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;what web development is, from scratch&lt;/a&gt; connects HTML, CSS and JavaScript into one whole.&lt;/p&gt;

&lt;p&gt;A real pricing page connected to real payments, accounts and plans is exactly the kind of thing a course builds step by step. For the blog, this is the concept: once you can see the four tricks, you can rebuild the page yourself.&lt;/p&gt;

&lt;p&gt;You can do this, and you have to. If you weren't capable, I wouldn't spend my time on you. Just don't give up, and you'll always have me on your side.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/pricing-table-from-scratch-css?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=pricing-table-from-scratch-css"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>html</category>
      <category>design</category>
    </item>
    <item>
      <title>Learning Web Development From Scratch With AI: What to Learn, What to Skip</title>
      <dc:creator>CodeFromScratch</dc:creator>
      <pubDate>Fri, 13 Nov 2026 18:20:12 +0000</pubDate>
      <link>https://dev.to/codefromscratch/learning-web-development-from-scratch-with-ai-what-to-learn-what-to-skip-aa1</link>
      <guid>https://dev.to/codefromscratch/learning-web-development-from-scratch-with-ai-what-to-learn-what-to-skip-aa1</guid>
      <description>&lt;p&gt;You want to learn web development, and everywhere you look someone says AI writes the code now. So you sit there wondering which parts are still worth your time, and which parts you'd only be learning to watch a machine do them faster. Today I'll sort it out for you: what to learn deeply, what to learn just enough to read, and what to skip for now, with a real bug an AI would happily write and a roadmap you can follow from scratch.&lt;/p&gt;

&lt;p&gt;Here's the short answer first. Learn deeply the things you need to judge code: reading it, how a request travels between the browser and the server, the shape of data, reading errors and basic security. Learn just enough syntax and framework detail to read it, because the AI and the docs can type it for you. Skip big-company architecture until a real problem asks for it.&lt;/p&gt;

&lt;p&gt;If you're a complete beginner, read this top to bottom, and please try the little exercise before you read my answer to it. If you've built a few things already, the parts for you are the order total bug, the live demo, and the section on using AI as a tutor instead of a ghostwriter. If you're experienced and you help juniors, there's a callout near the end about what they need from you now.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: nobody can tell you what's still worth learning
&lt;/h2&gt;

&lt;p&gt;Let me say the question out loud, because I think a lot of you carry it around quietly. You open a course. Lesson four is about three different ways to declare a variable. Then you open a chat window, describe a to-do app in two sentences, and a minute later you have one that works. So why would you spend a week on lesson four?&lt;/p&gt;

&lt;p&gt;And the internet gives you two answers, both loud. One side says learning to code is over, just learn to prompt. The other side says nothing has changed, so grind the fundamentals like it's 2015 and ignore the tools. I think both are wrong, and both are wrong in a way that costs you months.&lt;/p&gt;

&lt;p&gt;Here's where I stand, so you know who's talking. I work as a web developer, and I use AI for a big part of my work, day to day. I don't think AI will replace programmers. I think it changes how they work: fewer weeks of typing and debugging, more directing and checking. Whoever ignores that falls behind very fast, because these tools move fast. But directing only works if you understand what you're directing. That's this whole article in two sentences. The rest is about what "understand" actually means.&lt;/p&gt;

&lt;p&gt;Even developers who use these tools all the time don't fully trust them. In &lt;a href="https://survey.stackoverflow.co/2025/ai" rel="noopener noreferrer"&gt;Stack Overflow's 2025 Developer Survey&lt;/a&gt;, 84% of respondents said they use or plan to use AI tools in their development process, and yet more of them distrust the accuracy of those tools (46%) than trust it (33%). The most common frustration, named by 66%, was "AI solutions that are almost right, but not quite". Remember that phrase. &lt;strong&gt;Almost right is exactly the gap your learning has to close.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this feels impossible to answer right now
&lt;/h2&gt;

&lt;p&gt;The cause isn't that AI is magic. It's that AI made one part of the job very cheap, and that part happens to be the part you can see.&lt;/p&gt;

&lt;p&gt;When you watch someone program, what you see is typing. Syntax, brackets, the name of a function, the exact CSS property. That's the visible part, and it's what courses spend most of their time on, because it's easy to test: did you write the loop correctly or not. What you don't see is the other part. Deciding what to build. Noticing that a number is wrong. Asking who's allowed to see this data. Reading an error and knowing where to look. That part was always the hard part, and it's still yours.&lt;/p&gt;

&lt;p&gt;So "what should I learn" gets confusing, because the stuff that's easy to teach got cheap, and the stuff that matters was never really on the syllabus. I felt that second half long before AI showed up. I finished courses and still felt like I knew nothing, because nobody connected the exercises to real work. I wrote about that in &lt;a href="https://codefromscratch.org/blog/why-courses-leave-you-feeling-like-you-know-nothing?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;why courses leave you feeling like you know nothing&lt;/a&gt;. AI didn't create that gap. It just made it impossible to ignore.&lt;/p&gt;

&lt;p&gt;Here's the comparison I keep coming back to. Think about driving with GPS. The GPS picks the route, so you don't need to memorise every street in the city anymore. That part really did get cheap. But you still need to drive. You need the rules of the road, you need to read the signs, and you need to notice when the GPS tells you to turn into a lake. Nobody says "I have GPS, so I'll skip learning to drive". AI is the GPS. The code it writes is the route. Learning to program is still learning to drive.&lt;/p&gt;

&lt;h2&gt;
  
  
  The path: sort every topic into three boxes
&lt;/h2&gt;

&lt;p&gt;Instead of a giant list of technologies, I want to give you a sorting rule, because the tools will look different next year and a rule survives that. For any topic you meet, ask one question: if the AI got this wrong, would I notice, and what would it cost?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learn deeply: mistakes here are invisible and expensive. The code runs, the page looks fine, and the bug is still there. A wrong total, another person's data on the screen, a password sitting in a log file. You only catch these if you understand them.&lt;/li&gt;
&lt;li&gt;Learn enough to read: mistakes here are visible and cheap. A button in the wrong place, a CSS rule that doesn't apply, a function that got renamed in a new version. You see the problem, you check the docs or ask again, you fix it.&lt;/li&gt;
&lt;li&gt;Skip for now: things you won't need until you have the problem they solve. Learning them early isn't wrong, it's just expensive, because without the problem you have nothing to attach them to, and they don't stick.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice that the rule is about cost and visibility, not about how hard a topic is. Some easy things land in the first box. Some hard things land in the third. Let's fill the boxes, starting with the one that matters most.&lt;/p&gt;

&lt;h2&gt;
  
  
  Box one: learn these deeply
&lt;/h2&gt;

&lt;p&gt;These are the skills you'll use every single day, whether you type the code or an AI does. They're also the ones the AI can't do for you, because they're about judging its work. There are six of them: reading code, how a request travels, the shape of data, reading errors, the idea that the browser lies, and having an undo button. I'll spend the most time on the first one, because it's the one courses skip.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reading code comes before writing it
&lt;/h3&gt;

&lt;p&gt;Courses teach you to write code. In this new way of working you'll read far more code than you write, so reading is the skill to train first. Let me show you what I mean with a small test. Here's a function an AI could easily give you if you asked for "a function that calculates the order total from the form". Before you read my explanation, look at it and decide what it prints.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;total.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fromForm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shipping&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"4.99"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;orderTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;subtotal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;subtotal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shipping&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;orderTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fromForm&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Got your answer? Most people say 34.99. Ten times three is thirty, plus 4.99 for shipping. Here's what Node actually prints:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node total.js
304.99
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three hundred and four dollars and ninety-nine cents. Let's walk through it line by line, because every line matters here.&lt;/p&gt;

&lt;p&gt;The first line is the data as it arrives from a form. Look at the quotes. Everything that comes out of a form field is text, a string, even when the person typed a number. "10" in quotes isn't the number ten. It's the two characters 1 and 0. That's true even for an input with type="number": the browser still hands its value to your code as a string.&lt;/p&gt;

&lt;p&gt;The function line takes fields, which is that object with the three values. Nothing surprising yet.&lt;/p&gt;

&lt;p&gt;Then const subtotal = fields.price * fields.quantity. Here JavaScript quietly helps you. The star means multiply, and multiplying only makes sense for numbers, so JavaScript turns "10" and "3" into numbers and gives you 30. A real number. So far it looks like the code understands you.&lt;/p&gt;

&lt;p&gt;And then return subtotal + fields.shipping, where the help stops. The plus sign has two jobs in JavaScript: adding numbers and gluing text together. When one side is text, gluing wins. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition" rel="noopener noreferrer"&gt;MDN says it plainly&lt;/a&gt;: if one side is a string, the other operand is also converted to a string and they are concatenated. Concatenated just means glued end to end. So 30 becomes "30", it gets glued to "4.99", and you get "304.99".&lt;/p&gt;

&lt;p&gt;That's the "almost right, but not quite" from the survey, in four lines. It runs. There's no error message. With shipping set to "0" it shows 300 instead of 30, and with the shipping field left empty it shows 30, which happens to look correct. Someone testing it quickly could easily wave it through. The AI didn't do anything stupid here. It did something very common, and the only defence is a person who can look at that plus sign and ask: is this adding, or gluing?&lt;/p&gt;

&lt;h3&gt;
  
  
  Why the obvious fix is still almost right
&lt;/h3&gt;

&lt;p&gt;Here's the part that should make you want to learn this properly. When you paste that bug back to the AI and say "the total is wrong", a very common fix is to wrap the shipping in Number(), which converts text to a number:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;total.js (the quick fix)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;orderTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;subtotal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;subtotal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shipping&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now 4.99 works and you get 34.99. Done? Not quite. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#number_coercion" rel="noopener noreferrer"&gt;Number has rules of its own&lt;/a&gt;: empty or whitespace-only strings are converted to 0. So if the shipping field is left empty, Number("") is 0, not an error. An empty field silently becomes free shipping. And if someone types 4,99 with a comma, the way a lot of Europe writes decimals, Number gives you NaN. NaN means "not a number", and it spreads through every calculation it touches, so the total turns into NaN too. Each fix is almost right again. You have to know what you want before you can tell whether you got it.&lt;/p&gt;

&lt;h3&gt;
  
  
  What you want, written down: the checked version
&lt;/h3&gt;

&lt;p&gt;Here's the version I'd accept. It's longer, and every extra line is a decision somebody made on purpose.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;total-checked.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;toAmount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${label} is empty`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNaN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${label} must be a number, 0 or more`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;orderTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;toAmount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Price"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;toAmount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Quantity"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;shipping&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;toAmount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shipping&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Shipping"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;shipping&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;orderTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shipping&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"4.99"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;orderTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shipping&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Line by line again, because this is where the decisions live.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;function toAmount(raw, label) has one small job: turn one form value into a number, or refuse. The label is only there so the error message can say which field is wrong. Without it you'd get "something is empty", which helps nobody.&lt;/li&gt;
&lt;li&gt;if (raw.trim() === "") checks for an empty field. trim() removes spaces from both ends, so a field with only spaces in it counts as empty too. Delete this line and you're back to Number("") being 0. This line is the decision "empty is a mistake, not zero".&lt;/li&gt;
&lt;li&gt;const value = Number(raw) is the conversion, done once, on purpose, in one place where you can see it.&lt;/li&gt;
&lt;li&gt;if (Number.isNaN(value) || value &amp;lt; 0) catches anything that didn't convert, like "abc" or "4,99", and refuses negative amounts. Remove the value &amp;lt; 0 part and someone can order minus two items and get a discount you never offered.&lt;/li&gt;
&lt;li&gt;return value means only clean numbers ever leave this function.&lt;/li&gt;
&lt;li&gt;In orderTotal, every field now goes through the same door before any maths happens. And after that, the maths is the boring line you expected from the very start: price times quantity plus shipping.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's what it prints:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node total-checked.js
34.99
Error: Shipping is empty
    at toAmount &lt;span class="o"&gt;(&lt;/span&gt;total-checked.js:3:11&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I've cut the folder path and Node's internal lines from that output, nothing else. The first call prints 34.99. The second one stops with "Shipping is empty" instead of quietly charging nothing for shipping. A loud error while you're testing is a gift. A quiet wrong number in production is a bill.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Two honest limits of this example. First, in a real shop the price never comes from the browser at all. Anyone can change a form value in the browser's developer tools, so the server looks the price up itself; the vibe coding article shows exactly that attack with a live demo. Second, for real money, don't do maths with decimals like 4.99. Computers store them in binary, and in JavaScript 0.1 + 0.2 comes out as 0.30000000000000004. Real systems keep amounts in whole cents (499 instead of 4.99) and only format them as dollars on the screen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And all of this checking has to happen twice: once in the browser, so the person gets a quick, friendly message, and once on the server, because the browser is the one part of your app you don't control. That's the whole idea behind &lt;a href="https://codefromscratch.org/blog/login-form-validation-client-and-server?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;login form validation: why you check twice&lt;/a&gt;, and &lt;a href="https://codefromscratch.org/blog/zod-at-trust-boundaries?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;validating at trust boundaries with Zod&lt;/a&gt; shows the server side done properly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it: the first draft against the checked version
&lt;/h2&gt;

&lt;p&gt;Reading about it is one thing. Now try it. The form below runs both versions of the code. Leave the values as they are and press Calculate total with the first draft, then switch to the checked version and press it again. Then break it on purpose: empty the shipping field, type 4,99 with a comma, or set the quantity to -2. Watch what each version does with the same mistake.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; Order total: first draft vs checked version. It runs right in the page, so &lt;a href="https://codefromscratch.org/blog/learn-web-development-from-scratch-with-ai?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;try it in the original article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Notice that the first draft never complains. It doesn't know it's wrong, so it can't tell you. With minus two items it happily shows a total of -204.99. That's what makes this kind of bug dangerous: the code that should worry you most is often the code that looks the calmest.&lt;/p&gt;

&lt;p&gt;One small exercise before you move on, because this is exactly how you train reading. The checked version accepts 2.5 as a quantity. Half a T-shirt. Which line would you change, and to what? Try it yourself before you ask an AI. Then ask it, and compare. If your answer and its answer are different, that's the most useful conversation you'll have this week.&lt;/p&gt;

&lt;h2&gt;
  
  
  The rest of box one: requests, data, errors, security and undo
&lt;/h2&gt;

&lt;p&gt;Reading code is the first skill. The other five are what you need to know so you can read code and actually understand what it's doing to real people.&lt;/p&gt;

&lt;h3&gt;
  
  
  How a request travels
&lt;/h3&gt;

&lt;p&gt;Every web app, however fancy, is a conversation. The browser asks, the server answers. Opening a page, sending a form, clicking a like button: each one is a request going out and a response coming back. Once you really see that, a lot of confusion goes away. Why can't the browser read the database directly? Because the database lives on the server's side of the conversation. Why do we check a form twice? Because the browser's side of the conversation can be faked. Why is the page slow? Usually because it's waiting for an answer. I put all of this in order, with a tiny server you can build yourself, in &lt;a href="https://codefromscratch.org/blog/what-is-web-development-beginners-guide?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;what is web development: a complete beginner's guide&lt;/a&gt;. If you only read one other article after this one, make it that one.&lt;/p&gt;

&lt;p&gt;This belongs in box one because it decides where code runs, and where code runs decides who can see it and who can change it. An AI can put a secret key into code that ends up in the browser if nobody tells it not to. You can only stop that if you know which side of the conversation you're on.&lt;/p&gt;

&lt;h3&gt;
  
  
  The shape of data
&lt;/h3&gt;

&lt;p&gt;Almost everything you'll build is data being moved around and shown. A list of posts. A cart with items in it. A user with a name and an email. In JavaScript that's arrays, which are ordered lists, and objects, which are bundles of named values. In a database it's rows in tables. If you can look at a piece of data and say what shape it is, a list of things, one thing with fields, or a list of things where each one holds another list, you can follow almost any code an AI hands you. I showed the most common use of that in &lt;a href="https://codefromscratch.org/blog/render-lists-without-repeating-code?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;render lists without repeating code&lt;/a&gt;: one template, a list of data, a loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reading an error message without panicking
&lt;/h3&gt;

&lt;p&gt;Errors are going to be a big part of your life, AI or not. AI tools will often show you an error with a guess about the cause attached, and you need to be able to read the error yourself to know if the guess makes sense. Here's a tiny program with a bug in it:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;greet.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Emily"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"James"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Hi, "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node greet.js
Hi, Emily
greet.js:4
  &lt;span class="nb"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Hi, "&lt;/span&gt; + users&lt;span class="o"&gt;[&lt;/span&gt;index&lt;span class="o"&gt;]&lt;/span&gt;.name&lt;span class="o"&gt;;&lt;/span&gt;
                               ^

TypeError: Cannot &lt;span class="nb"&gt;read&lt;/span&gt; properties of undefined &lt;span class="o"&gt;(&lt;/span&gt;reading &lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    at greet &lt;span class="o"&gt;(&lt;/span&gt;greet.js:4:32&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again I've cut the folder path and Node's own lines underneath. Read every error in the same three steps, always in this order.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What happened: "TypeError: Cannot read properties of undefined (reading 'name')". In plain words, you asked for .name on something that doesn't exist. Whatever sits just to the left of .name is undefined.&lt;/li&gt;
&lt;li&gt;Where: greet.js:4:32 means the file greet.js, line 4, column 32. Node even draws a little arrow under the exact spot. The line "at greet" tells you which function you were in when it happened.&lt;/li&gt;
&lt;li&gt;Why: now you think. On line 4, the thing to the left of .name is users[index], so users[index] was undefined. Which index? The second call passed 2. The array holds two users, and arrays count from 0, so the only valid positions are 0 and 1. Position 2 is empty.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice that the error told you the what and the where perfectly, and said nothing about the why. The why is always yours. An AI can often guess it too, but if you can't follow its reasoning, you can't tell a good guess from a confident wrong one. And the fix depends on what you want, which is the theme of this whole article. Should greet(2) be impossible, so the code that called it is the real bug? Or should it return a friendly "user not found"? Neither answer is right in general. You decide, and that decision is your job, not the tool's.&lt;/p&gt;

&lt;h3&gt;
  
  
  Security starts with one idea: the browser lies
&lt;/h3&gt;

&lt;p&gt;You don't need to be a security expert to start. You need one idea, learned so deeply it becomes a reflex: anything that comes from the browser can be changed by the person using it. Form values, hidden fields, prices, user ids in the address bar. The server checks everything again, and the server decides who is asking. I built &lt;a href="https://codefromscratch.org/blog/what-is-vibe-coding?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;what is vibe coding&lt;/a&gt; around exactly this mistake, because it's the one AI-built apps make most often, and &lt;a href="https://codefromscratch.org/blog/production-grade-code-checklist?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;what separates hobby apps from real ones&lt;/a&gt; turns it into a checklist you can run against your own project.&lt;/p&gt;

&lt;p&gt;And here's a mistake I made myself. When I started, I never once thought about what happens when a thousand real people have accounts on something I built. How do I protect their accounts from someone guessing passwords? What happens when they forget theirs? What do I do when my own bug hurts them? None of that crossed my mind. It doesn't need to scare you. It just needs to be on your list from the beginning, not after the first problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Git is your undo button
&lt;/h3&gt;

&lt;p&gt;Version control sounds like something for big teams. It's actually the one tool that makes working with AI safe for a beginner. An AI agent can change a dozen files in one go. Without a saved point to go back to, one bad change can wreck code that worked an hour ago. Git gives you that saved point. Here's the whole routine, and it's only a handful of commands.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Terminal&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add -A
git commit -m &lt;span class="s2"&gt;"Order total works, before the refactor"&lt;/span&gt;
&lt;span class="c"&gt;# let the AI make its change, then look at what it did:&lt;/span&gt;
git diff --stat
git diff total.js
git restore total.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;git add -A picks up every change in the project folder, and git commit saves all of it as a point in history, with a message. Write the message for future you: what works right now.&lt;/li&gt;
&lt;li&gt;The line starting with # is a comment. Bash ignores it; it's only there to show you where the AI's work happens.&lt;/li&gt;
&lt;li&gt;git diff --stat is the summary: which files changed and how many lines in each. If you asked for a fix in one file and the summary shows five, that's your first question for the AI.&lt;/li&gt;
&lt;li&gt;git diff total.js shows the actual lines, with a minus in front of what was removed and a plus in front of what was added. This is where reading code pays off. You don't read the whole project again, only what changed.&lt;/li&gt;
&lt;li&gt;git restore total.js throws away the uncommitted changes in that one file and brings back the version from your last commit. Careful: those changes are gone for good, so look at the diff before you restore. It also doesn't touch brand new files that git isn't tracking yet; a file the AI created stays where it is.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run that sequence on the order total from earlier, with the quick Number() fix as "the AI's change", and the diff shows exactly one line with a minus and one with a plus. After the restore, the file is back to the committed version, bug and all, which is the point: you're back to a state you know. The &lt;a href="https://git-scm.com/docs/git-restore" rel="noopener noreferrer"&gt;git restore documentation&lt;/a&gt; lists every option if you need more than this.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Tested with: every code sample in this article was run with Node.js 24.14.1 and Git 2.53 on Windows, and the live demo was run in Microsoft Edge 157, including a 320 pixel wide frame. The advice about using AI doesn't depend on a particular tool; it works the same with a chat assistant or a coding agent.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Box two: learn just enough to read
&lt;/h2&gt;

&lt;p&gt;This box is where AI really does save you weeks, and I'm happy to say so. These are things you should recognise and understand when you see them, but you don't need to be able to type them from memory.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Exact syntax. Whether it's forEach or for...of, where the semicolons go, the order of arguments in a function you use twice a year. Know what a loop is for and when you need one. Your editor, the docs and the AI will remember the spelling.&lt;/li&gt;
&lt;li&gt;Every CSS property. Learn the box model, how flexbox and grid think, and how to make a page work on a phone. You don't need to memorise every property and every value.&lt;/li&gt;
&lt;li&gt;Framework details. Learn what a component is, what runs on the server and what runs in the browser, and how data gets into a page. The exact names of functions change between versions, and that's exactly where AI answers are weakest, because they may come from an older version.&lt;/li&gt;
&lt;li&gt;Regular expressions, build settings and config files. Know what they're for. Let the AI write the pattern, then test it against examples you chose yourself, including the ugly ones.&lt;/li&gt;
&lt;li&gt;SQL beyond the basics. Learn SELECT, WHERE and JOIN, and what an index is for. Longer queries you can read, run against test data and ask questions about.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the CSS part, two articles will get you to "I can read this" quickly: &lt;a href="https://codefromscratch.org/blog/html-css-beginners-build-first-web-page?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;HTML and CSS for beginners: build your first web page&lt;/a&gt; for the foundations, and &lt;a href="https://codefromscratch.org/blog/css-flexbox-vs-grid-real-layouts?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;flexbox vs grid on real layouts&lt;/a&gt; for how layout actually gets decided.&lt;/p&gt;

&lt;p&gt;There's one rule that makes box two safe: for anything you didn't write yourself, you either test it or check it against the official documentation. A function name that doesn't exist fails loudly, and that's fine, you'll see it. A function that exists but works differently in the newest version fails quietly. The docs tell you which version they describe. An AI's answer often doesn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Box three: skip it for now
&lt;/h2&gt;

&lt;p&gt;Skip for now means not yet. It doesn't mean never, and it doesn't mean these things don't matter. It means you've got nothing to hang them on yet, so they won't stick, and the time is better spent in box one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Microservices, Kubernetes and the architecture of very large companies. These solve the problems of hundreds of developers and huge traffic. A first real app with its first users needs one server, one database and backups.&lt;/li&gt;
&lt;li&gt;Five frameworks at once. Pick one way to build, learn it until you can make something small without a tutorial open, and only then compare it with others.&lt;/li&gt;
&lt;li&gt;Chasing every new AI tool. New ones appear constantly. Learn one well enough to direct it: how to give it context, how to ask for a plan, how to review what it did. That skill carries over to the next tool; the buttons don't.&lt;/li&gt;
&lt;li&gt;Algorithm puzzles as your main training. If you're preparing for interviews at companies that test them, that's a separate goal and a fair one. For learning to build for the web, a real project teaches more than a hundred puzzles about prime numbers.&lt;/li&gt;
&lt;li&gt;Your own login system for real users. Learn how sessions and password hashing work, absolutely. But for an app real people use, reach for a well-tested library. Understanding the idea is a great exercise; running a homemade one in production is a risk you don't need.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to see which pieces I'd actually pick for a full app today, and why, &lt;a href="https://codefromscratch.org/blog/modern-full-stack-2026?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;modern full-stack development in 2026&lt;/a&gt; walks through the whole stack. Read it as a map, not as a to-do list for this month.&lt;/p&gt;

&lt;p&gt;Now, there's something that sounds like it contradicts this box, so let me clear it up. I believe a good programmer thinks three steps ahead: what happens with more users, what happens when something fails, what's the Plan B. That's true, and it doesn't clash with skipping Kubernetes. Thinking ahead costs you a sentence in your plan: "if this grows, the database is the first thing to watch". Building for a million users before you have ten costs you months. Think ahead always. Build ahead only when the problem shows up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use AI as a tutor, not a ghostwriter
&lt;/h2&gt;

&lt;p&gt;Everything above assumes you use AI while you learn. Please do. The real question is how. A ghostwriter writes for you and you put your name on it, and you learn nothing. A tutor makes you do the work and helps when you're stuck. It's the same tool either way, and the difference is entirely in what you ask it.&lt;/p&gt;

&lt;p&gt;Here's how I'd use it while learning, roughly in this order:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Try first, even badly. Write your own attempt before you ask. A wrong attempt gives you and the AI something concrete to talk about, and the gap between your attempt and the right answer is exactly the thing you need to learn.&lt;/li&gt;
&lt;li&gt;Ask for a hint, not the answer. Something like: "Don't write the code. Tell me in one sentence what's wrong with my approach." One sentence is often enough.&lt;/li&gt;
&lt;li&gt;Make it explain every line. When it does write code, ask what each line does and what breaks if you delete it. The second question teaches you more than the first.&lt;/li&gt;
&lt;li&gt;Ask what it assumed. "List everything you assumed about the input and the user." The bugs usually live somewhere in that list.&lt;/li&gt;
&lt;li&gt;Make it quiz you. "Ask me three questions about this code and don't give me the answers." If you can't answer them, you don't own that code yet.&lt;/li&gt;
&lt;li&gt;Type the core yourself once. Not everything. But the heart of a feature, typed by your own hands one time, sticks in a way that pasted code never does.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Experienced developers use the same habits in a grown-up form: they talk the plan through first, then go step by step, and read what changed after every step. I described that routine in &lt;a href="https://codefromscratch.org/blog/what-is-vibe-coding?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;the vibe coding article&lt;/a&gt;, with the four questions I ask about every change.&lt;/p&gt;

&lt;p&gt;And one realisation that took me a while. When the AI's answer isn't what I imagined, most of the time I could have asked better. It's a machine running maths over whatever you gave it. It can't know what's in your head, or what you saw on some other site last week. Learning to say exactly what you want is a programming skill in itself, and it's the same skill as writing good code: being precise about what should happen, and what must never happen.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Be careful with what you paste. Never paste passwords, API keys, the contents of a .env file or real people's data into a chat with any AI tool. If you need help with code that uses a secret, swap in a fake value first. It's one habit worth having from day one, because once something is pasted, you can't take it back.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A roadmap for learning web development from scratch
&lt;/h2&gt;

&lt;p&gt;Here's the order I'd learn web development in today. It's a guideline, not a course, and there are no deadlines on it, because everyone's pace is different. Each step ends with something small you can build, and each step says where AI fits in.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: HTML, CSS and how a page reaches the screen
&lt;/h3&gt;

&lt;p&gt;What a page is made of, what the browser does with it, and how to make it readable on a phone. Start with &lt;a href="https://codefromscratch.org/blog/html-css-beginners-build-first-web-page?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;building your first web page&lt;/a&gt;. Build one page about something you like, and make it work at phone width. Use AI to review your HTML for meaning and accessibility, not to write it for you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: JavaScript, data and the page
&lt;/h3&gt;

&lt;p&gt;Arrays, objects, functions, loops, events, and changing the page from code. This is where the order total lives. Build a list that renders from data, with a filter or a sort button. Use AI to explain lines and to quiz you, and do the exercise from this article before you ask it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: forms and the server
&lt;/h3&gt;

&lt;p&gt;Requests and responses for real, a tiny server, and checking input on both sides. Build a form that saves something on a server and refuses bad input in the browser and again on the server. Use AI to ask what it assumed, and compare its list with yours.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: a database, and who is asking
&lt;/h3&gt;

&lt;p&gt;Rows and tables, one honest query, and signing in with a well-tested library instead of a homemade one. Build a list that belongs to the signed-in person, where one person can never see another's data, and write one test that proves it. This is where box one stops being theory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: shipping it
&lt;/h3&gt;

&lt;p&gt;Git, putting it online, environment variables for secrets, and reading logs when something goes wrong. &lt;a href="https://codefromscratch.org/blog/deploying-full-stack-apps-to-vercel-the-definitive-guide?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;Deploying full-stack apps to Vercel&lt;/a&gt; covers the putting-it-online part. Build: give it a real address and send it to one friend. Use AI for the mechanical checks, like listing every place where input enters your app, and keep the judgement calls for yourself.&lt;/p&gt;

&lt;p&gt;The order matters more than the speed. And if you can, pick one real project that runs through all five steps, small and easy at first, harder each time. A simple shop page that grows into a shop with a cart. A list of your own things that grows into an inventory with accounts. That way every concept arrives attached to a reason, and that's what makes it stick.&lt;/p&gt;

&lt;p&gt;About pace: you'll hear that you must study two or three hours every single day. I don't agree, especially at the start. Some days the code just won't go in, and forcing it teaches you to hate it. Take a day or two off when you need it, but don't let a break turn into a month, because without a rhythm nothing becomes a habit. One percent better a day, for a year, beats one heroic weekend and then nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  So that's all it is
&lt;/h2&gt;

&lt;p&gt;Strip away the noise and it's simple. AI made typing cheap. It didn't make judging cheap. So you learn the things that let you judge: reading code, how a request travels, the shape of data, reading errors, the idea that the browser lies, and how to undo a bad change. You learn just enough of the rest to read it and test it. And you leave big-company architecture alone until a real problem asks for it.&lt;/p&gt;

&lt;p&gt;The order total is the whole article in four lines. Anyone can get code that runs. The person who builds things that last, and the person worth hiring, is the one who looks at return subtotal + fields.shipping and asks: is this adding, or gluing?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you're experienced and you help juniors: the review is where they learn now. When a junior opens a pull request an AI helped write, ask them to explain one function line by line and to say what breaks if a line goes. If they can, the tool helped them. If they can't, it wrote for them, and the kind thing is to say so early. Asking them to describe the expected behaviour as a test before any code exists trains exactly the box-one skills.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What to be careful about, and the Plan B
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Tutorial hell moved into the chat window. Asking an AI forever feels like progress, the same way watching tutorials did. If you haven't built something you can explain with the chat closed, you're watching, not learning.&lt;/li&gt;
&lt;li&gt;Confident and outdated. AI answers sound equally sure whether they're right or describe a version from two years ago. For anything tied to a framework or a library, check the version in the official docs.&lt;/li&gt;
&lt;li&gt;Skipping box one because the output looks finished. The order total looked finished too. Looking finished isn't a test.&lt;/li&gt;
&lt;li&gt;Comparing yourself to demos. Demos show the happy path in two minutes. Real apps are mostly the unhappy paths: empty fields, wrong input, slow networks, and people doing things you never expected.&lt;/li&gt;
&lt;li&gt;Trying to keep up with everything. Learning while the tools change every month is tiring. Pick one tool, one stack and one project, and let the rest go past you for a while. It'll still be there.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the Plan B. Some day the AI will be down, out of credits, or simply wrong in a way it can't see. Your Plan B is the boring stuff: the official docs, the error message read in three steps, a git restore, and a person you can ask. Not knowing something yet is fine. Plenty of people working in companies right now don't know everything and ask for help all the time. The difference is that they know what to ask, and after this article, you know a lot more about what to ask too.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to learn next
&lt;/h2&gt;

&lt;p&gt;If you're starting from zero, go to &lt;a href="https://codefromscratch.org/blog/what-is-web-development-beginners-guide?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;what is web development&lt;/a&gt; next and follow it in order, then &lt;a href="https://codefromscratch.org/blog/html-css-beginners-build-first-web-page?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;build your first web page&lt;/a&gt;. If you've got the basics, read &lt;a href="https://codefromscratch.org/blog/login-form-validation-client-and-server?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;login form validation&lt;/a&gt; and then &lt;a href="https://codefromscratch.org/blog/zod-at-trust-boundaries?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;Zod at trust boundaries&lt;/a&gt;, because that's box one in practice. And if you'd like a second map from the people who write the browser docs, the free &lt;a href="https://developer.mozilla.org/en-US/curriculum/" rel="noopener noreferrer"&gt;MDN Curriculum&lt;/a&gt; is organised the same way: core skills first, extensions later.&lt;/p&gt;

&lt;p&gt;You can do this, and you have to. If you weren't capable, I wouldn't spend my time on you. Just don't give up, and you'll always have me on your side.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article first appeared on &lt;a href="https://codefromscratch.org/blog/learn-web-development-from-scratch-with-ai?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;CodeFromScratch&lt;/a&gt;, where the live demos run right in the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Free: The Production Checklist.&lt;/strong&gt; 24 checks to run before a web app meets real users, each linked to the article that explains it. &lt;a href="https://codefromscratch.org/newsletter?utm_source=dev.to&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=learn-web-development-from-scratch-with-ai"&gt;Get it with the newsletter&lt;/a&gt;: one short email when a new article goes live, unsubscribe in one click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
