React warns that a div is nested inside a p tag
<div> cannot appear as a descendant of <p>Short answer
A p element may contain only phrasing content, and the HTML parser closes a paragraph as soon as a div, list or other block element starts. React warns because the browser then builds a different tree than your JSX describes. Replace the p with a div, or the inner div with a span.
Fix it fast
1Find out which cause you have
Open the browser console in development. It names the tags involved, so you can see which p holds the offending element.
# find paragraphs in your source that contain a block child grep -rn --include=*.jsx --include=*.tsx -A3 "<p[ >]" src | grep -E "<(div|ul|ol|table|section|h[1-6])"2Match what you see, then jump to its fix
- 1
validateDOMNesting names the tag, and the JSX shows it between <p> and </p>A div, list, heading or table is written directly inside a pFix - 2
The JSX looks fine, <p><Badge /></p>, but the warning names a div under the pA child component renders a block element inside a pFix - 3
A hydration mismatch error on a server-rendered page, on a route that has a p holding a divThe same mistake breaks server-rendered pages as a hydration errorFix
- 1
What does the error look like?
<div> cannot appear as a descendant of <p>Text content does not match server-rendered HTML
Cause 1 of 3
A div, list, heading or table is written directly inside a p
1Check
The content model of p is phrasing content. A p end tag may also be left out when the next tag is a div, ul, ol, table, section, heading or another p, which means the parser closes the paragraph for you.
grep -rn --include=*.tsx -B1 -A4 "<p" src/components/Card.tsx2Fix
Make the outer element a div, or make the inner element a span if the content really is inline text.
// before
<p className="note">
<div className="icon" /> Saved
</p>
// after
<div className="note">
<span className="icon" /> Saved
</div>3Verify
Reload the page. The warning is gone from the console.
npm run devConfirmed by html.spec.whatwg.org
Cause 2 of 3
A child component renders a block element inside a p
1Check
The warning is about rendered output, not about your JSX. Open the child component and look at its outermost element.
grep -n "return" -A3 src/components/Badge.tsx2Fix
Change the child's root to a span, or move the child out of the paragraph.
// Badge.tsx
export function Badge({ children }) {
return <span className="badge">{children}</span>;
}3Verify
The console no longer names a div under a p.
npm run devConfirmed by nextjs.org
Cause 3 of 3
The same mistake breaks server-rendered pages as a hydration error
1Check
Next.js lists p inside p, div inside p, ul or ol inside p, and interactive content such as a inside a or button inside button as causes of hydration mismatch.
curl -s http://localhost:3000/ | grep -n -A2 "<p"2Fix
Fix the nesting itself. Do not hide it with suppressHydrationWarning, which is meant for unavoidable differences such as timestamps and works only one level deep.
// a link inside a link, a button inside a button and p inside p
// are fixed the same way: one valid element per level
<div>
<p>Intro text</p>
<p>Second paragraph</p>
</div>3Verify
Reload with the console open. The hydration error is gone.
npm run build && npm run startConfirmed by nextjs.org
How do I stop it coming back?
- Default to div for wrappers and keep p for text that is only text and inline elements.
- Read the tags named in the warning to find the p and the element inside it.
- Run the app in development and click through the main pages before a release, because the nesting warnings only print there.
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
React hydration failed: the server HTML and the first browser render differ
Text content does not match server-rendered HTML
Hydration fails when the first render in the browser produces different HTML from the HTML the server sent.
5 causes, each with a fixWeb apps
Upgrading to Next.js 16: middleware becomes proxy, and the other things that break
Missing Required default.js for Parallel Route
Next.js 16 renames middleware.ts to proxy.ts and its exported function to proxy.
6 causes, each with a fixWeb apps
Warning: Extra attributes from the server in the console
Text content does not match server-rendered HTML
React found attributes on an element in the server HTML that its own render did not produce.
3 causes, each with a fixWeb apps
Next.js stops with 'document is not defined' while it renders on the server
ReferenceError: document is not defined
Next.js renders your components on the server first, where there is no document.
3 causes, each with a fixWeb apps
A custom error from the server arrives at the client as a generic message
error.digest holds a hash instead of your message
Next.js hides the message of errors thrown in Server Components in production, to avoid leaking details.
3 causes, each with a fixWeb apps
useState fails in a child component in the Next.js App Router
React client hook in Server Component
In the App Router every component is a Server Component unless a file above it is marked otherwise, and Server Components cannot use state or effects.
3 causes, each with a fix