Not found
A 404 page: a large typographic 404 with a compass in place of the zero, a short apology, a search Input, popular destinations as Card links in a responsive Grid, and a Report a broken link button that thanks you with a toast.
Error 404
We can’t find that page
It may have moved, or the link may have a typo. Sorry about that. Search below, or pick up from one of these.
Popular destinations
Followed a link from another page?
Source · recipes/not-found.tsx
'use client'
import { Body, Button, Card, Grid, Heading, Input, Stack, Text, toastSuccess } from '@blocks/design-system'
import { Activity, BookOpen, Compass, CreditCard, LifeBuoy, type LucideIcon, Newspaper, Rocket, Search } from 'lucide-react'
import { useState } from 'react'
import styles from './not-found.module.css'
const destinations: { href: string; title: string; description: string; icon: LucideIcon }[] = [
{ href: '#getting-started', title: 'Getting started', description: 'Set up a workspace in ten minutes.', icon: Rocket },
{ href: '#guides', title: 'Guides', description: 'Step-by-step help for common tasks.', icon: BookOpen },
{ href: '#pricing', title: 'Pricing', description: 'Plans for teams of every size.', icon: CreditCard },
{ href: '#changelog', title: 'Changelog', description: 'What shipped this month.', icon: Newspaper },
{ href: '#support', title: 'Support', description: 'Talk to a person on weekdays.', icon: LifeBuoy },
{ href: '#status', title: 'Status', description: 'Live uptime for every service.', icon: Activity },
]
// A calm 404: say what happened, then offer three ways forward (search, the
// most visited pages, and telling us the link is broken).
export default function NotFound() {
const [query, setQuery] = useState('')
const [reported, setReported] = useState(false)
const terms = query.trim().toLowerCase()
const shown = destinations.filter((destination) => `${destination.title} ${destination.description}`.toLowerCase().includes(terms))
return (
<Stack as="section" gap="xl" align="center" textAlign="center" aria-labelledby="not-found-title" dangerouslySetClassName={styles.page}>
<Stack gap="md" align="center">
<p className={styles.code}>
<span className={styles.srOnly}>Error 404</span>
<span aria-hidden>4</span>
<span className={styles.zero} aria-hidden>
<Compass strokeWidth={1.5} />
</span>
<span aria-hidden>4</span>
</p>
<Heading as="h2" id="not-found-title" fontSize="xl">
We can’t find that page
</Heading>
<Body color="text-muted" margin="none" dangerouslySetClassName={styles.lede}>
It may have moved, or the link may have a typo. Sorry about that. Search below, or pick up from one of these.
</Body>
</Stack>
<search className={styles.searchArea}>
<form
className={styles.search}
onSubmit={(event) => {
event.preventDefault()
if (terms) toastSuccess(`Searching the help center for “${query.trim()}”`)
}}
>
<span className={styles.field}>
<Search aria-hidden size={16} className={styles.searchIcon} />
<Input
type="search"
size="lg"
aria-label="Search the help center"
placeholder="Search help"
value={query}
onChange={(event) => setQuery(event.target.value)}
/>
</span>
<Button type="submit" variant="primary" size="lg">
Search
</Button>
</form>
</search>
<Stack gap="md" width="full">
<Heading as="h3" fontSize="xs" color="text-muted" dangerouslySetClassName={styles.label}>
Popular destinations
</Heading>
{shown.length > 0 ? (
<Grid as="ul" columns={{ base: 1, sm: 2 }} gap="sm" dangerouslySetClassName={styles.list}>
{shown.map(({ href, title, description, icon: Icon }) => (
<li key={href}>
<Card as="a" href={href} padding="lg" borderRadius="xl" dangerouslySetClassName={styles.destination}>
<span className={styles.icon}>
<Icon aria-hidden size={18} />
</span>
<span className={styles.destinationText}>
<Text fontWeight="semibold">{title}</Text>
<Text fontSize="sm" color="text-muted">
{description}
</Text>
</span>
</Card>
</li>
))}
</Grid>
) : (
<Text fontSize="sm" color="text-muted" role="status">
No popular pages match “{query.trim()}”. Press Search to look everywhere.
</Text>
)}
</Stack>
<Stack gap="sm" align="center">
<Text fontSize="sm" color="text-muted">
Followed a link from another page?
</Text>
<Button
type="button"
variant="ghost"
aria-disabled={reported}
onClick={() => {
if (reported) return
setReported(true)
toastSuccess('Thanks. We’ll fix the link that brought you here.')
}}
>
{reported ? 'Broken link reported' : 'Report a broken link'}
</Button>
</Stack>
</Stack>
)
}How it works
- The big numerals are
aria-hidden; a visually hidden “Error 404” and theh2carry the meaning. The 404 grows from thexxxxlto thexxxxxlfont size with a container query, so it fits a phone. - Typing in the search narrows the destinations as you go, and submitting searches everywhere. The form sits in a
<search>landmark. - Each destination is a
Cardrendered as a link (as="a"), so the whole card is one target with one focus ring. - After a report the button stays in place and focusable but
aria-disabled, so a second press does nothing and focus is never lost.
App-owned CSS
.page {
container-type: inline-size;
padding: var(--ds-space-xl) 0;
}
/* The 404 is display type; the compass stands in for the zero */
.code {
display: flex;
align-items: center;
gap: var(--ds-space-sm);
margin: 0;
font-family: var(--ds-font-heading);
font-size: var(--ds-font-size-xxxxl);
font-weight: var(--ds-font-weight-bold);
line-height: 1;
letter-spacing: -0.04em;
color: var(--ds-color-text);
}
.zero {
display: grid;
place-items: center;
inline-size: 0.8em;
block-size: 0.8em;
color: var(--ds-color-accent-text);
background-color: var(--ds-color-accent-subtle);
border-radius: var(--ds-border-radius-circle);
& svg {
inline-size: 55%;
block-size: 55%;
}
}
@container (width >= 30rem) {
.code {
font-size: var(--ds-font-size-xxxxxl);
}
}
.lede {
max-inline-size: 28rem;
}
.searchArea {
inline-size: 100%;
max-inline-size: 28rem;
}
.search {
display: flex;
gap: var(--ds-space-sm);
}
.field {
position: relative;
flex: 1;
min-inline-size: 0;
& input {
padding-left: calc(var(--ds-space-lg) + var(--ds-icon-size-sm) + var(--ds-space-md));
}
}
.searchIcon {
position: absolute;
top: 50%;
left: var(--ds-space-lg);
translate: 0 -50%;
color: var(--ds-color-text-muted);
pointer-events: none;
}
.label {
letter-spacing: 0.06em;
text-transform: uppercase;
}
.list {
margin: 0;
padding: 0;
list-style: none;
text-align: left;
}
.destination {
display: flex;
align-items: flex-start;
gap: var(--ds-space-md);
block-size: 100%;
box-sizing: border-box;
color: inherit;
text-decoration: none;
transition:
border-color var(--ds-duration-fast) var(--ds-easing-standard),
background-color var(--ds-duration-fast) var(--ds-easing-standard);
&:hover {
background-color: var(--ds-color-bg-subtle);
border-color: var(--ds-color-border-strong);
}
&:focus-visible {
outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
outline-offset: var(--ds-space-xs);
}
}
.icon {
display: grid;
flex-shrink: 0;
place-items: center;
inline-size: var(--ds-control-height-md);
block-size: var(--ds-control-height-md);
color: var(--ds-color-accent-text);
background-color: var(--ds-color-accent-subtle);
border-radius: var(--ds-border-radius-md);
}
.destinationText {
display: grid;
gap: var(--ds-space-xs);
}
.srOnly {
position: absolute;
inline-size: var(--ds-space-xxs);
block-size: var(--ds-space-xxs);
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
.destination {
transition: none;
}
}