Skip to content
Browse documentation

A 404 with a search and a puppy: Fetch sniffs as you type, sprints off to fetch the results and comes back with a newspaper, or a stick.

Used for404 pagesDocsEmpty searchOld links

Want a reactive 3D character for this state? See Hairline Mascots (free MIT starter or all 8 characters).

Install with the shadcn CLI

$ npx shadcn@latest add @hairline/not-found

Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/not-found.json. More

Templates

Need the whole page?

65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.

Where it’s used

  • 404 pages

    The not-found page of a site or app, with a way to find what moved.

  • Docs

    A missing docs page that searches the docs straight away.

  • Empty search

    The no-results state of any search, with a stick for comfort.

  • Old links

    Retired campaign or blog URLs that should still lead somewhere.

What it handles for you

Most 404 pages leave people to guess. This block shows the address that failed, searches as soon as they type, and always offers somewhere to go.

Instead of wiring upa 404 pagea site search boxdebounce and abortsearch resultssuggested links
  1. Search that waits

    search runs 350ms after typing stops; each newer query aborts the older request through its AbortSignal.

  2. Results as links

    { title, href, hint } rows, up to five, that drop in as they arrive.

  3. Never a dead end

    With nothing found (or before searching) your popular pages show instead.

  4. The address

    path shows exactly what wasn’t found.

  5. Failures said plainly

    If search throws, Fetch comes back empty-mouthed and says he couldn’t get out.

  6. A way home

    homeHref is always there under the list.

Overview

A 404 page is usually a big number, an apology and a link home. This one goes and looks. A 404 is engraved into the lit stage and Fetch, an illustrated golden retriever puppy, sits in front of it with his tongue out. Start typing what you were after and he puts his nose to the ground, twitching with every key. When the typing stops he sprints off the edge of the stage, his legs switching between two strides, and your search runs; type again and the older search is aborted. He runs back in with a newspaper in his mouth and the results drop in under the field, or, if nothing matched, sits there sheepishly with a stick (“fetch() came back with a stick”) and your popular pages come back. Under the puppy it is a real recovery page: the missing address, a labelled search with a clear button, links that are links, and a way home.

States

lost
Fetch sits by a 404 engraved in outline on the lit stage, panting, wagging and tilting his head; “Fetch lost this page too”. Popular pages are listed under the search.
sniff
While you type: nose to the ground, sniffing, until 800ms after the last key; “Fetch has a scent”.
fetch
350ms after typing stops: he gallops off the right edge (520ms, accelerating), a real run cycle at 15 frames a second; “Fetch is fetching…”.
found
He gallops back in (700ms, slowing), then sits wagging proudly with a newspaper; the results drop in 50ms apart; “Fetch found 2”.
stick
No results: he comes back with a stick and looks sheepish, “fetch() came back with a stick”, and the links return under “Try one of these”.
offline
search throws: he comes back with nothing and says he couldn’t get out; the links stay.

Usage

usage.tsx
import { NotFound } from "@/components/not-found";<NotFound  path={pathname}  links={[{ title: "Pricing", href: "/pricing" }]}  search={(query, signal) => fetch(`/api/search?q=${encodeURIComponent(query)}`, { signal }).then((r) => r.json())}/>

Depends on lucide-react, installed for you by the CLI along with the keyframes it needs.

Works with

As the Next.js not-found page

app/not-found.tsx renders for every unmatched route; read the path on the client and search your own index.

example.tsx
"use client";import { usePathname } from "next/navigation";import { NotFound } from "@/components/not-found";export default function NotFoundPage() {  const pathname = usePathname();  return (    <main className="grid min-h-dvh place-items-center p-6">      <NotFound        path={pathname}        links={[          { title: "Pricing", href: "/pricing" },          { title: "Docs", href: "/docs", hint: "Guides and reference" },        ]}        search={async (query, signal) => {          const res = await fetch(`/api/search?q=${encodeURIComponent(query)}`, { signal });          if (!res.ok) throw new Error("Search failed");          return res.json(); // [{ title, href, hint }]        }}      />    </main>  );}

Props

search
(query: string, signal: AbortSignal) => Promise<NotFoundResult[]>
Find pages for a query: { title, href, hint? }. Called 350ms after typing stops; aborted when a newer query starts.
links= []
NotFoundResult[]
Shown before anyone searches and when nothing is found.
path
string
The address that wasn’t found, shown in the line under the title.
homeHref= "/"
string
Where Take me home goes.
name= "Fetch"
string
What the puppy is called in his lines.

Accessibility and motion

  • The search is a labelled input with a clear button; results and links are plain links in a list that is announced politely when it changes.
  • Fetch is decoration (aria-hidden) and animated: sitting, sniffing, running and both returns are loops of frames cut from a generated animation, shipped inside fetch-art.ts as WebP strips (145KB), so the install is complete. Each loop is one Web Animation (no frame loop); a rAF loop moves him across the stage only while he runs.
  • One frame loop outside React moves him and sleeps when he’s still; his breathing is a compositor animation. The scene is drawn at 364 × 168 and scaled to the stage.
  • With reduced motion he doesn’t run or twitch: his pose changes in place and the results appear without rising.
  • Built from Input and Text morph, which the CLI installs with it. No animation library.

Requirements

React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

The CLI also installs Input, Text morph.

Source

"use client";import * as React from "react";import { ArrowUpRight, Search } from "lucide-react";import { Fetch, type FetchHandle } from "./fetch-dog";import { Input } from "./input";import { TextMorph } from "./text-morph";import { EASE_OUT, useInteractionReducedMotion } from "./ui-interaction-motion";/* ───────────────────────────────────────────────────────── * NOT FOUND: Fetch goes and looks for it * *   lost     a 404 engraved into the lit stage and Fetch, a *            puppy, sitting in front of it; your popular pages *            are listed under the search *   sniff    typing: nose to the ground, a twitch per key *   fetch    350ms after the typing stops, search() runs and he *            sprints off the edge of the stage; a newer query *            aborts the older one *   found    he runs back in with a newspaper and the results *            drop in under the field *   stick    nothing found: he comes back with a stick, and *            your links come back too * * search(query, signal) is yours: your site search, your docs * index, a fetch to your own API. * ───────────────────────────────────────────────────────── */export interface NotFoundResult {  title: string;  href: string;  /** A short line under the title: a section, a path, a date. */  hint?: string;}export interface NotFoundProps {  /** Find pages for a query; aborted when a newer one starts. */  search: (query: string, signal: AbortSignal) => Promise<NotFoundResult[]>;  /** Shown before anyone searches, and when nothing is found. */  links?: NotFoundResult[];  /** The address that wasn't found, shown under the title. */  path?: string;  homeHref?: string;  /** What the puppy is called in his lines. */  name?: string;  className?: string;}const mix = (color: string, amount: number, into = "transparent") => `color-mix(in oklab, ${color} ${amount}%, ${into})`;const PF = "var(--primary-foreground)";const CARD: React.CSSProperties = {  backgroundImage: `linear-gradient(180deg, var(--card), ${mix("var(--card)", 95, "var(--foreground)")})`,  boxShadow: `0 0 0 1px var(--border), inset 0 1px 0 ${mix("var(--background)", 85)}`,};const STAGE: React.CSSProperties = {  backgroundColor: "var(--primary)",  backgroundImage: [    `radial-gradient(60% 70% at 26% 100%, ${mix(PF, 22)} 0%, transparent 70%)`,    `linear-gradient(175deg, transparent 40%, ${mix("black", 22)} 100%)`,  ].join(", "),  boxShadow: `inset 0 1px 0 ${mix(PF, 36)}, inset 0 0 0 1px ${mix(PF, 12)}`,};type Phase = "idle" | "typing" | "fetching" | "found" | "none" | "error";export function NotFound({ search, links = [], path, homeHref = "/", name = "Fetch", className = "" }: NotFoundProps) {  const reduced = useInteractionReducedMotion();  const baseId = React.useId();  const dog = React.useRef<FetchHandle>(null);  const [query, setQuery] = React.useState("");  const [phase, setPhase] = React.useState<Phase>("idle");  const [results, setResults] = React.useState<NotFoundResult[]>([]);  const [shown, setShown] = React.useState(0);  const run = React.useRef<{ timer: number; ctrl: AbortController | null }>({ timer: 0, ctrl: null });  const searchRef = React.useRef(search);  React.useEffect(() => {    searchRef.current = search;  });  React.useEffect(() => () => {    window.clearTimeout(run.current.timer);    run.current.ctrl?.abort();  }, []);  const change = (next: string) => {    setQuery(next);    window.clearTimeout(run.current.timer);    run.current.ctrl?.abort();    const q = next.trim();    if (!q) {      setPhase("idle");      dog.current?.back("sit");      return;    }    setPhase("typing");    dog.current?.sniff();    run.current.timer = window.setTimeout(async () => {      const ctrl = new AbortController();      run.current.ctrl = ctrl;      setPhase("fetching");      dog.current?.go();      try {        const found = await searchRef.current(q, ctrl.signal);        if (ctrl.signal.aborted) return;        setResults(found);        setShown((n) => n + 1);        setPhase(found.length ? "found" : "none");        dog.current?.back(found.length ? "paper" : "stick");      } catch {        if (ctrl.signal.aborted) return;        setPhase("error");        dog.current?.back("sit");      }    }, 350);  };  const mood =    phase === "fetching"      ? `${name} is fetching…`      : phase === "typing"        ? `${name} has a scent`        : phase === "found"          ? `${name} found ${results.length === 1 ? "one" : results.length}`          : phase === "none"            ? "fetch() came back with a stick"            : phase === "error"              ? `${name} couldn’t get out`              : `${name} lost this page too`;  const list = phase === "found" ? results : phase === "fetching" && results.length ? results : links;  const listTitle = phase === "found" || (phase === "fetching" && results.length) ? "Found" : phase === "none" ? "Try one of these" : "Popular pages";  return (    <section aria-labelledby={`${baseId}-title`} className={`relative w-full max-w-[380px] rounded-[28px] p-2 text-card-foreground ${className}`} style={CARD}>      {/* Its natural width where the parent sizes to its content, without forcing it on narrow screens. */}      <div aria-hidden="true" data-natural-width className="grid h-0" style={{ gridTemplateColumns: "minmax(0, 380px)" }} />      <div className="@container w-full">        <div className="relative overflow-clip rounded-[22px] text-primary-foreground" style={STAGE}>          <Fetch ref={dog} reduced={reduced}>            {/* the signature: a 404 engraved into the stage, outlines only */}            <span              aria-hidden="true"              className="absolute select-none font-semibold leading-none tracking-[-0.06em]"              style={{ left: 166, top: 34, fontSize: 104, color: "transparent", WebkitTextStroke: `1px ${mix(PF, 34)}` }}            >              404            </span>            {/* the floor he sits on */}            <span aria-hidden="true" className="absolute inset-x-0 h-px" style={{ top: 152, background: mix(PF, 18) }} />          </Fetch>          <p className="absolute left-3.5 top-3 z-10 text-[12.5px] font-medium text-primary-foreground/85">            <TextMorph>{mood}</TextMorph>          </p>        </div>        <div className="px-3 pb-2 pt-3">          <h2 id={`${baseId}-title`} className="text-[15px] font-medium tracking-[-0.01em]">            Page not found          </h2>          <p className="mt-0.5 text-[12.5px] text-muted-foreground">            {path ? (              <>                Nothing lives at <span className="font-mono text-[12px] text-foreground">{path}</span>.{" "}              </>            ) : (              "This page moved or never existed. "            )}            Ask {name} to find it.          </p>          <Input            className="mt-3"            aria-label="Search the site"            placeholder="Search pages"            leading={<Search />}            clearable            value={query}            onValueChange={change}            autoComplete="off"            spellCheck={false}          />          {list.length > 0 && (            <div className="mt-3">              <p className="px-1 text-[11.5px] font-medium text-muted-foreground">                <TextMorph>{listTitle}</TextMorph>              </p>              <ul key={`${listTitle}-${shown}`} className="mt-1" aria-live="polite">                {list.slice(0, 5).map((r, i) => (                  <li key={r.href} style={reduced ? undefined : { animation: `ui-fade-up 360ms ${EASE_OUT} ${i * 50}ms backwards` }}>                    <a                      href={r.href}                      className="group flex min-h-10 items-center gap-2 rounded-[10px] px-2 py-1.5 outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/40"                    >                      <span className="min-w-0 flex-1">                        <span className="block truncate text-[13px] font-medium">{r.title}</span>                        {r.hint && <span className="block truncate text-[11.5px] text-muted-foreground">{r.hint}</span>}                      </span>                      <ArrowUpRight className="size-3.5 shrink-0 text-muted-foreground transition-transform duration-200 group-hover:-translate-y-0.5 group-hover:translate-x-0.5" />                    </a>                  </li>                ))}              </ul>            </div>          )}          <a href={homeHref} className="mt-2 inline-block px-1 text-[12.5px] text-muted-foreground underline decoration-border underline-offset-2 hover:text-foreground">            Take me home          </a>        </div>      </div>    </section>  );}export default NotFound;

Registry item: /r/not-found.json