# Not Found

> A page-not-found page in plain words, with the closest real page, a search box and places to go next.

```tsx
'use client';

import { ActionLink, NotFound } from '@brand-studio/ui';

const pages = ['/', '/shop', '/shop/ethiopia-guji', '/shop/huila-washed', '/shop/house-espresso', '/brew-guides', '/subscriptions'];
const links = [
  { href: '/shop', title: 'Shop', description: 'Every coffee we roast this month.' },
  { href: '/brew-guides', title: 'Brew guides', description: 'Recipes for filter, espresso and cold brew.' },
  { href: '/subscriptions', title: 'Subscriptions', description: 'Fresh bags every two or four weeks.' },
];

// The links point at pages of a made-up shop, so the demo keeps clicks and searches on this page.
export default function NotFoundDemo() {
  return (
    <div onClickCapture={event => { if ((event.target as HTMLElement).closest('a')) event.preventDefault(); }} onSubmitCapture={event => event.preventDefault()} style={{ width: '100%', display: 'grid', justifyItems: 'center' }}>
      <NotFound
        as="h2"
        path="/shop/ethiopia-gujii"
        pages={pages}
        links={links}
        search="/search"
        searchLabel="Search coffees"
        action={<ActionLink href="/" tone="secondary">Go to the home page</ActionLink>}
      />
    </div>
  );
}
```

## Installation

```sh
npm install @brand-studio/ui
```

React 18 or 19 is a peer dependency. Import the stylesheet once and wrap the app in a brand theme:

```tsx
import '@brand-studio/ui/styles.css';
import { BrandTheme, NotFound } from '@brand-studio/ui';
import brand from './brand.json';

<BrandTheme palette={brand.tokens} mode="system">
  {/* your app */}
</BrandTheme>
```

## Usage

```tsx
import { NotFound } from '@brand-studio/ui';
```

```tsx
<NotFound
  pages={sitemapPaths}
  links={[{ href: '/shop', title: 'Shop', description: 'Every coffee we roast this month.' }]}
  search="/search"
/>
```

Without `path`, it reads the address from the browser after it loads. When the address is a typo or two away from one of `pages`, it offers that page first. It compares the address part by part, so one wrong letter in a long address counts as one edit. The search box sends `q` to `search`, filled in with the words from the address. Keep `links` to three or four places people most often want.

For a page that moved or was removed, say so in `title` and `description`, and put the new page in `action`:

```tsx
<NotFound title="This page has moved" description="The brew guides now live in one place." action={<ActionLink href="/brew-guides">Go to brew guides</ActionLink>} />
```

`art` takes a picture or an effect such as `GlitchText` above the heading. Pass `as` to pick the heading level when the page already has an `h1`.

## Accessibility

- The default words say what happened and what to do, with no error code and no blame.
- The search form is a search landmark with a label for screen readers.
- Serve the page with a 404 status, so search engines drop the address.

## API Reference

| Prop | Type | Default |
|---|---|---|
| `title?` | `React.ReactNode` | `'Page not found'` |
| `description?` | `React.ReactNode` | `'Check the address for a typo. If you followed a link here, the page may have moved.'` |
| `path?` | `string` | – |
| `pages?` | `string[]` | – |
| `links?` | `NotFoundLink[]` | – |
| `search?` | `string` | – |
| `searchLabel?` | `string` | `'Search'` |
| `guessLabel?` | `string` | `'Did you mean'` |
| `art?` | `React.ReactNode` | – |
| `action?` | `React.ReactNode` | – |
| `as?` | `React.ElementType` | – |
| `className?` | `string` | `''` |

Source: https://brandstudio.js.org/docs/components/not-found/
