Layouts in Next.js allow you to create shared UI that is reused across multiple pages, such as headers, footers, sidebars, and navigation menus. Layouts help keep your application consistent and reduce code duplication.
A layout is a special file named layout.js (or layout.tsx) used in the App Router (app/ directory).
It wraps pages and persists across route changes.
The root layout is required in every Next.js app using the App Router.
Applies to all pages
Includes <html> and <body> tags
Loads global styles
You can create layouts for specific routes by adding a layout.js file inside a folder.
This layout will apply only to /dashboard routes.
Layouts are nested automatically based on the folder structure.
Each layout wraps the layout and page below it.
Layouts do not re-render on navigation
State inside layouts is preserved
Improves performance and user experience
Global styles are usually imported in the root layout.
You can define metadata for SEO inside layouts.
| Feature | Layout | Page |
|---|---|---|
| Reusable UI | Yes | No |
| Persistent | Yes | No |
| Required | Root layout only | Yes |
| Contains HTML/Body | Root layout | No |
Layouts are a core feature of Next.js that help build structured, consistent, and scalable applications. By using root and nested layouts, you can efficiently manage shared UI across your app.
Take quizzes related to this topic and see where you stand!
Start Quiz Now