Next.js hydration error: Text content does not match server-rendered HTML
The HTML rendered on the server differs from the first render in the browser, usually from window/localStorage, Date(), random values, or invalid HTML nesting. Make the first client render match the server and move browser-only values into useEffect.
Cause: Rendering logic produces different output on server and client (browser APIs, time, randomness, invalid nesting, extensions).
How to fix it
- Open the dev overlay to see which element differs.
- Move browser-only reads (
window,localStorage) intouseEffector a client-only component. - Fix invalid nesting such as
<div>inside<p>. - Use
useIdinstead of random IDs; for unavoidable cases like timestamps usesuppressHydrationWarningsparingly.
Example
Illustrative example, not from a customer project.
- <span>{new Date().toLocaleString()}</span>
+ const [time, setTime] = useState<string>()
+ useEffect(() => setTime(new Date().toLocaleString()), [])
+ <span>{time}</span>
FAQ
Could a browser extension cause it?
Yes. Next.js docs list extensions that modify HTML as a cause. Test in a clean profile.
Is `suppressHydrationWarning` a fix?
It is an escape hatch that works one level deep. Use it only for content that must differ, like timestamps.
Get a $149 diagnosis See pricing Launching soon? The Launch Path gets you ready for $1,195 flat.
- Fixed, or we keep working free until it is (within the written scope).
- A human reviews every fix before it ships.
- read-only access; fixes arrive as pull requests you merge
- Your $149 diagnosis is credited in full toward any paid job.