Next.js: “Hydration failed because the initial UI does not match what was rendered on the server”
Last verified: October 18, 2026
What it means
Server and browser render different HTML, e.g. from dates, Math.random, window, or invalid nesting. Newer React versions word it as "Hydration failed because the server rendered HTML didn't match the client."
How to fix it
Move browser-only code into useEffect and fix invalid HTML nesting like <div> inside <p>.
Paste this into Next.js
Stop retrying previous fixes. I'm getting this error: "Hydration failed because the initial UI does not match what was rendered on the server". Likely cause: Server and browser render different HTML, e.g. from dates, Math.random, window, or invalid nesting. Newer React versions word it as "Hydration failed because the server rendered HTML didn't match the client." Before editing, show me the relevant files and confirm the root cause. Then: Move browser-only code into useEffect and fix invalid HTML nesting like <div> inside <p>. Change only what's necessary, don't delete working code, don't add new libraries unless required, and tell me exactly what you changed and how to verify it.
Your error's a bit different? Paste it and get a fix prompt written for your exact case.
Break the loop — 3 free fixes Still stuck? Get a human fix