Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4133 pages
Next.js and React

Next.js shows an error page saying the root layout has no <html> or <body>

Your error

Missing <html> and <body> tags in the root layout.1 more line it can show

Fix it fast

Most common cause, 1 of 3

app/layout returns children without the document tags

Return the two tags from the top layout and put your wrapper inside body.

Fix
// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <main>{children}</main>
      </body>
    </html>
  )
}
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

In the App Router, any layout.js with no layout above it is a root layout, and every root layout has to return the <html> and <body> elements itself. The error appears when app/layout.js returns only a wrapper or a fragment, or when a route group has its own top layout without them. Add both tags to every root layout.

  • Applies to Next.js 15.5, React 19, Node.js 24
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

List every layout file and work out which ones have no layout above them. Those are the root layouts the rule applies to.

Run this first
find app -name 'layout.*' | sort

Then find the line you see in this list and open its fix:

  1. 1app/layout returns children without the document tagsEvery route shows the error, and app/layout.js returns a div, a main element or a fragment
  2. 2A route group has its own root layout without the tagsOnly routes inside one group, such as /cart under app/(shop), show the error
  3. 3The html element is returned only under some conditionThe error comes and goes with a locale, a feature flag or an auth state

What does the error look like?

  • Missing <html> and <body> tags in the root layout.
  • One route works while another route of the same app shows the error overlay

Cause 1 of 3

app/layout returns children without the document tags

You seeEvery route shows the error, and app/layout.js returns a div, a main element or a fragment

Check

Open app/layout.js (or .tsx). Next.js does not add <html> or <body> for you, so a layout that only wraps children in some element leaves the document without them.

Check
grep -nE '<html|<body' app/layout.*

Fix

Return the two tags from the top layout and put your wrapper inside body. Page titles and meta tags belong in the metadata export, not in a hand-written head.

Fix
// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <main>{children}</main>
      </body>
    </html>
  )
}

Verify

Restart next dev and open the home page. The overlay is gone and the page source starts with <html lang="en">.

Verify
curl -s http://localhost:3000/ | head -c 200

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 3

A route group has its own root layout without the tags

You seeOnly routes inside one group, such as /cart under app/(shop), show the error

Check

When there is no app/layout.js, each group's top layout becomes a separate root layout. One group may have html and body while another group's layout returns only a section.

Check
ls app/layout.* 2>/dev/null || echo 'no top-level layout'
grep -LE '<html' app/\(*\)/layout.*

Fix

Give every group-level root layout its own html and body, or add one shared app/layout.js and turn the group layouts into ordinary nested layouts without the document tags.

Fix
// app/(shop)/layout.tsx
export default function ShopLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body><section>{children}</section></body>
    </html>
  )
}

Verify

Open a route from each group. All of them render; moving between groups that use separate root layouts does a full page load, which is expected.

Verify
curl -s http://localhost:3000/cart | grep -c 'Missing <html>'

Confirmed by nextjs.org

Did this fix it?

Cause 3 of 3

The html element is returned only under some condition

You seeThe error comes and goes with a locale, a feature flag or an auth state

Check

Look for an early return, a ternary or a provider in the root layout that sometimes returns children without the document tags, for example while a locale is still unknown.

Check
grep -nE 'return|\?' app/layout.* app/*/layout.*

Fix

Always return html and body from the root layout, and put conditions inside body. A value such as the lang attribute can change; the two elements themselves must always be there.

Fix
export default async function LocaleLayout({ children, params }) {
  const { locale } = await params
  return (
    <html lang={locale ?? 'en'}>
      <body>{children}</body>
    </html>
  )
}

Verify

Load the route in each state that used to fail (each locale, signed in and signed out).

Verify
npx next build

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Keep one file as the only place that renders html and body, unless you really need separate root layouts.
  • When you add a route group with its own top layout, add the document tags in the same commit.
  • Use the Metadata API for head content so nobody is tempted to build the document by hand.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.