React & Next.js errors · Error 02 of 7
Next.js “Hydration failed” / text content does not match
By Muhammad Abdullah, full-stack, mobile and ai automation developer · Last reviewed
Hydration failed because the server rendered HTML didn't match the clientShort answer
The HTML rendered on the server differs from the first render in the browser. Remove browser-only or time-dependent values from the initial render, and fix invalid HTML nesting.
Common causes
- Using
Date.now(),Math.random(), or locale formatting that differs between server and browser. - Checking
typeof windowor readinglocalStorageduring render. - Invalid nesting such as a <div> or <p> inside a <p>.
- Browser extensions that modify the page before React hydrates.
How to fix it
Render client-only values after mount:
const [now, setNow] = useState<string | null>(null); useEffect(() => setNow(new Date().toLocaleString()), []);Fix invalid HTML nesting reported in the console.
For unavoidable differences on a single element (like a timestamp), add
suppressHydrationWarningto that element only.
Older React versions show this as “Text content does not match server-rendered HTML”.