Keep global navigation and footer persistent across routes.
Application-wide shell
Next.js 16+ · Directive
Use a layout file to define UI shared by a route segment and its descendants. Export a component that renders its required children prop; the root layout also defines the document's html and body elements.
Create a layout file that exports a React component receiving children. Next.js places the wrapped route content in children; layouts can exist at nested route levels, while the root layout supplies the document shell.
export default function Layout({ children }: { children: React.ReactNode }) { return <>{children}</> }| Name | Type | Description |
|---|---|---|
children | React.ReactNode | The route segments wrapped by the layout, supplied during rendering; this prop is required. |
A React element containing shared layout UI and the rendered children.
import type { ReactNode } from 'react'
export default function RootLayout({
children,
}: Readonly<{ children: ReactNode }>) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}Save this as app/layout.tsx. It supplies the required document elements and renders the active route inside the shared root UI.
Application-wide shell
Section-specific shell
Persistent interactive UI
A layout is a shared UI component for a route segment and its descendants. It receives children, which contains the page or nested layout being wrapped.
Follow-up: How does nesting work? A layout in a deeper route folder wraps that segment's descendants, and parent layouts wrap the deeper layout through children.
The app directory must have a root layout. The root layout defines html and body and commonly contains globally shared UI such as navigation or a footer.
Follow-up: What happens if html and body are omitted? The root layout is invalid because Next.js does not create those document tags automatically.
Layouts preserve state, remain interactive, and do not rerender during navigation. This makes them suitable for persistent application chrome around changing page content.
Follow-up: When should route-specific UI use a page instead? Use page for UI unique to one route, while layout is for UI shared by a segment and its children.
page.jstemplate.jserror.jsloading.jsnot-found.jsroute groups