# Next.js 404 page

> Build a Next.js 404 with not-found.js and notFound() in the App Router or pages/404.js, and learn when a not-found response still returns 200.

Canonical: https://scaplet.com/seo/nextjs/404

Guide Next.js Next.js · 404 page

Build a Next.js 404 with not-found.js and notFound() in the App Router or pages/404.js, and learn when a not-found response still returns 200.

3 min

read

5

sources

Oct 29, 2026

updated

Scaplet Editorial Team

author

In one line

In the Next.js App Router, add `app/not-found.js` for the 404 UI and call `notFound()` from `next/navigation` when data is missing. Next.js returns a 404 status before streaming starts, and injects `<meta name="robots" content="noindex" />` either way. In the Pages Router, create `pages/404.js`, which is statically generated at build time.

30-second check

## Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2F404%20(%22Next.js%20404%20page%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2F404%20(%22Next.js%20404%20page%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2F404%20(%22Next.js%20404%20page%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2F404%20(%22Next.js%20404%20page%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

## At a glance

4 facts from the sources below

not-found.js

App Router file

notFound() or unmatched URL

Trigger

pages/404.js

Pages Router file

robots noindex

Auto-injected tag

_01_Where each 404 mechanism lives

## Which file for which job

Need

### Custom 404 for the whole site

App Router

`app/not-found.js`, which also handles any unmatched URL

Pages Router

`pages/404.js`, statically generated at build time

Need

### 404 for a missing record

App Router

Call `notFound()` in the render path

Pages Router

Return `<Error statusCode={...} />` from `next/error` yourself

Need

### Different 404 for one section

App Router

`not-found.js` in that route segment

Pages Router

Not documented on the custom error page

Need

### One 404 with multiple root layouts

App Router

`global-not-found.js` (experimental)

Pages Router

Not applicable

Need

### Server error page

App Router

Not covered here

Pages Router

`pages/500.js` or `pages/_error.js`

_02_Worth knowing

## App Router: not-found.js and notFound()

### No `return` needed

`notFound()` throws a `NEXT_HTTP_ERROR_FALLBACK;404` error and terminates [rendering](/glossary/rendering) of the route segment, so calling it is enough.

### Call it in the render path

A call left in an un-awaited promise throws where nothing catches it and no not-found UI renders. In development the server logs `⨯ unhandledRejection: NEXT_HTTP_ERROR_FALLBACK;404`.

### Where it works

`notFound()` can be invoked in Server Components, Server Functions, and Route Handlers.

### Metadata

The root `app/not-found.js` supports exporting `metadata` or `generateMetadata` to set the title and other head tags.

### Theme

The default not-found UI follows the operating system color scheme and doesn't read an app-level theme, so supply your own `not-found.js` for control.

app/not-found.tsx

```
import Link from 'next/link' export default function NotFound() { return ( <div> <h2>Not Found</h2> <p>Could not find requested resource</p> <Link href="/">Return Home</Link> </div> ) }
```

app/user/[id]/page.tsx

```
import { notFound } from 'next/navigation' export default async function Profile({ params, }: { params: Promise<{ id: string }> }) { const { id } = await params const user = await fetchUser(id) if (!user) { notFound() } // ... }
```

_03_Good to know

## Will it actually return a 404 status?

Not always. Next.js says that before streaming starts it returns a `404` [status code](/glossary/http-status-codes), but after streaming starts the status code remains `200` and the not-found UI renders in the response. Next.js injects `<meta name="robots" content="noindex" />` in both cases, which keeps the URL out of [search results](/glossary/serp) even at 200. Some crawlers may label those responses as soft 404s.

Streaming starts when a Suspense fallback renders, such as a `loading.tsx`, or when a Server Component suspends under a `<Suspense>` boundary. Calling `notFound()` before that point preserves the 404. If you need a real 404 for compliance or analytics, run the check before the body streams. For a 404, Next.js says you can check the [slug](/glossary/url-slug) in Proxy, then rewrite to a not-found route or return a 404 response, and to keep Proxy checks fast.

Google's reasoning is straightforward: it doesn't index URLs that return a 4xx status code, while a 2xx response whose content looks like an error message appears as a [soft 404](/glossary/soft-404) in [Search Console](/glossary/google-search-console). For deleted pages with a replacement, a redirect is the better answer; see [Next.js redirects](/seo/nextjs/redirects).

A loading.tsx can turn your 404 into a 200

If a route has `loading.tsx` and your data fetch happens below it, the response may have started streaming before `notFound()` runs. Test a missing slug with `curl -I`, not just in the browser.

_04_Check it

## global-not-found.js for multiple root layouts

`global-not-found.js` is experimental. Next.js documents it for apps with multiple root layouts, or a root layout built from top-level dynamic segments such as `app/[country]/layout.tsx`, where one layout can't compose a global 404. It bypasses normal rendering, so import your global styles and fonts in the file, and it must return a full HTML document with `<html>` and `<body>`.

next.config.ts

```
import type { NextConfig } from 'next' const nextConfig: NextConfig = { experimental: { globalNotFound: true, }, } export default nextConfig
```

_05_Checklist

## Pages Router: pages/404.js

First_2_
Next.js provides a static 404 page by default, because server-rendering an error page for every visit increases load on the server.

`pages/404.js` is statically generated at build time, and you can use `getStaticProps` in it.

Next_1_
`pages/_error.js` is only used in production. In development you get an error with the call stack.

Then_1_
To render the built-in page for another status, import `Error` from `next/error` and pass `statusCode`. The `Error` component does not support `getStaticProps` or `getServerSideProps`.

pages/404.js

```
export default function Custom404() { return <h1>404 - Page Not Found</h1> }
```

_06_Check it

## Check it worked

Run it on a made-up URL and on a missing dynamic slug such as `/user/does-not-exist`. Next.js says it returns a `404` status before streaming starts, so that is what you want to see for the dynamic slug. If the dynamic route prints `200`, look for a Suspense boundary or `loading.tsx` above the check, and confirm the `robots` meta tag is present either way.

Status code and robots tag for a missing URL

```
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/does-not-exist-123 curl -s https://example.com/does-not-exist-123 | grep -i 'name="robots"'
```

Questions

## Asked a lot.

2 questions people ask next, answered from the sources on this page.

_01_ How do I create a custom 404 page in Next.js?

In the App Router, add `app/not-found.js`. In the Pages Router, create `pages/404.js`, which Next.js statically generates at build time.

_02_ Does notFound() always send a 404 status?

No. Before streaming starts Next.js returns 404. After streaming starts the status stays 200, though it still injects a robots noindex meta tag.

Sources · 5

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- nextjs.org
- google.com

1. 01 [not-found.js | Next.js Documentation](https://nextjs.org/docs/app/api-reference/file-conventions/not-found) nextjs.org · checked 2026-11-01
2. 02 [notFound | Next.js Documentation](https://nextjs.org/docs/app/api-reference/functions/not-found) nextjs.org · checked 2026-11-01
3. 03 [loading.js (Status codes) | Next.js Documentation](https://nextjs.org/docs/app/api-reference/file-conventions/loading) nextjs.org · checked 2026-11-01
4. 04 [Custom Errors | Next.js Documentation (Pages Router)](https://nextjs.org/docs/pages/building-your-application/routing/custom-error) nextjs.org · checked 2026-11-01
5. 05 [HTTP status codes, and network and DNS errors | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/http-network-errors) developers.google.com · checked 2026-11-01

## Keep learning

[All platform guides](/seo)

[Learn Next.js redirects Frameworks](/seo/nextjs/redirects) [Related Soft 404 Crawling](/glossary/soft-404) [Read next Next.js SEO Frameworks](/seo/nextjs) [Do Run a free site audit Free, about two minutes](/site-audit)

Nearby in platform guides
[Mintlify redirects](/seo/mintlify/redirects) [Next.js SEO](/seo/nextjs)

More in Next.js SEO
[Next.js 404 page](/seo/nextjs/404) [Next.js AI crawlers](/seo/nextjs/ai-crawlers) [Next.js canonical tags](/seo/nextjs/canonical-tags) [Next.js Google Analytics](/seo/nextjs/google-analytics) [Next.js image SEO](/seo/nextjs/image-seo) [Next.js lazy loading](/seo/nextjs/lazy-loading) [Next.js noindex](/seo/nextjs/noindex) [Next.js redirects](/seo/nextjs/redirects) [Next.js robots.txt](/seo/nextjs/robots-txt) [Next.js structured data](/seo/nextjs/structured-data) [Next.js title and meta description](/seo/nextjs/title-and-meta) [Next.js XML sitemap](/seo/nextjs/xml-sitemap)

Terms on this page
[Rendering](/glossary/rendering) [HTTP status codes](/glossary/http-status-codes) [SERP](/glossary/serp) [URL slug](/glossary/url-slug) [Soft 404](/glossary/soft-404) [Google Search Console](/glossary/google-search-console)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

Run the free audit, then approve the fixes. Every change can be undone.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
