File conventions

Pages Router custom Document

Customize the document shell rendered on the server. Keep application state, event handlers and per-page titles out of this shell. The Head export from next/document is distinct from next/head; the latter is used for individual page metadata. Example context: Next.js 16.x documentation lane; illustrative snippet or file tree, not executed. Exact candidate patch 16.4.6 remains unverified. Expected behavior / verification: Inspect the initial HTML for lang and framework scripts. Compare soft navigation: the custom document is not a client-navigation component.

Formal Syntax & Structure

nextjs syntaxnextjs
pages/_document.tsx; Html, Head, Main, NextScript

Working Example

Example Snippetnextjs
import { Html, Head, Main, NextScript } from 'next/document';export default function Document() {  return <Html lang="en"><Head/><body><Main/><NextScript/></body></Html>;}
Next.js Reference