Text content does not match server-rendered HTML
The text output on the client differed from what the server compiled.
Usually happens because:
- ☑ Rendering Date objects directly
- ☑ Rendering Math.random() values
- ☑ Dynamic browser localized text translations
🔍 Quick Checklist:
📊 Where this usually happens (estimated occurrence)
What is Text content does not match server-rendered HTML?
A subclass of hydration warnings, this occurs when text characters (rather than HTML element tags) differ between the server build and client rendering (such as rendering current timestamps or localized messages that change dynamically).
Common Causes
- Rendering new Date() directly inside component text blocks.
- Displaying random numbers (Math.random()) or client-specific sizes.
- Varying texts dynamically using client geolocation settings.
Common Mistakes
- Printing localized currencies or times directly on server outputs without locking the timezone locale configurations.
How to Fix
Framework-Specific Examples
No framework examples required for this informational status.
Wrong: Dynamic Date Render
export default function Clock() {
return <div>{new Date().toLocaleTimeString()}</div>;
}Correct: Mounted Client State Date
import { useState, useEffect } from 'react';
export default function Clock() {
const [time, setTime] = useState('');
useEffect(() => {
setTime(new Date().toLocaleTimeString());
}, []);
return <div>{time}</div>;
}Best Practices
- Isolate dynamic state updates inside client hooks.
Frequently Asked Questions (FAQ)
Q: Does this warning crash the application?
No. In development, it prints a console warning. In production, React attempts to patch the text mismatch but it indicates poor render efficiency.
Q: How do I suppress hydration warnings?
Add `suppressHydrationWarning` to the specific JSX tag. It only goes one level deep.
Q: Why does the browser console show a long HTML diff?
React prints the exact diff between server static output and client output to help you locate the text mismatch.
Q: Can CSS changes cause text matches to fail?
No. Only text content and HTML nodes structure changes trigger this warning.