Free auditStart free
GuideNext.js · 404 page

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 withChatGPTClaudePerplexityGoogleAI Mode

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
02Worth knowing

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

No `return` needed

notFound() throws a NEXT_HTTP_ERROR_FALLBACK;404 error and terminates 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()
  }

  // ...
}
03Good to know

Will it actually return a 404 status?

Not always. Next.js says that before streaming starts it returns a 404 status code, 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 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 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 in Search Console. For deleted pages with a replacement, a redirect is the better answer; see Next.js redirects.

04Check 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
05Checklist

Pages Router: pages/404.js

First2
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.
Next1
pages/_error.js is only used in production. In development you get an error with the call stack.
Then1
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>
}
06Check 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.

01How 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.

02Does 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. 01not-found.js | Next.js Documentationnextjs.org · checked 2026-11-01
  2. 02notFound | Next.js Documentationnextjs.org · checked 2026-11-01
  3. 03loading.js (Status codes) | Next.js Documentationnextjs.org · checked 2026-11-01
  4. 04Custom Errors | Next.js Documentation (Pages Router)nextjs.org · checked 2026-11-01
  5. 05HTTP status codes, and network and DNS errors | Google Search Centraldevelopers.google.com · checked 2026-11-01
Free · 2 minutes

Tools point. Agencies advise. This one ships.

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

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane