Error: Hydration failed because the initial UI does not match what was rendered on the server
The HTML rendered on the server differs from the first client render, so React (Next.js/Remix) can’t attach to it.
Seen on:
React
Meaning
Server-side rendering requires the first client render to produce identical markup. Values that differ between server and browser — dates, random IDs, window/localStorage, locale formatting — or invalid HTML nesting cause mismatches.
Common causes
- Rendering
Date.now(),Math.random()or locale-dependent formatting - Reading
window,localStorageor media queries during render - Invalid nesting (
<div>inside<p>,<a>inside<a>) - Browser extensions modifying the DOM
- Different data on server vs client
⚡ Quick fix
- Move browser-only values into
useEffect(render a placeholder first) - Fix invalid HTML nesting
- Use
suppressHydrationWarningonly for unavoidable text like timestamps - Render client-only components with
dynamic(() => import(...), { ssr: false })in Next.js
Detailed fix by platform
React
- Client-only value after mount:jsx
function LocalTime({ iso }) { const [text, setText] = useState(''); // same on server and first client render useEffect(() => setText(new Date(iso).toLocaleString()), [iso]); return <time dateTime={iso}>{text}</time>; }
How to diagnose
- Diff — Which text/element differs (dev overlay shows it)?
- Browser APIs — window/localStorage/Date used in render?
- HTML — Invalid nesting?
- Extensions — Reproduce in a clean profile
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026