Hydration failed because the initial UI does not match | SheCodes

Server and browser disagree · Usually quick to fix

Hydration failed because the initial UI does not match

The page looked different when the server rendered it vs when the browser took over. This is common with dates, random values, or browser-only code.

What the error looks like

Error: Hydration failed because the initial UI does not match what was rendered on the server

Why it happens

Next.js renders your page on the server first, then the browser takes over. If they produce different HTML, you get this error. Common causes: using Date, Math.random(), or checking window/localStorage during render.

How to fix it

  1. Wrap browser-only code (window, localStorage, etc.) in a useEffect hook
  2. Use suppressHydrationWarning on elements with dynamic content like dates
  3. Make sure your component renders the same thing on server and client

Ask your AI coding tool to fix it

Paste this prompt into Claude Code, Cursor, Bolt or Lovable, with your own error in place of the example.

I'm getting this error and I need help understanding and fixing it:

```
Error: Hydration failed because the initial UI does not match what was rendered on the server
```

Please:
1. Explain what this error means in plain English
2. Tell me the most likely cause
3. Give me the exact code changes or commands I need to fix it
4. Show me how to prevent this error in the future

Got a different error?

Paste any error into the free Error Decoder and get it explained in plain English, with a fix prompt.

Decode my error

More common errors explained