Skip to content
IT glossary
FrontendUpdated December 3, 2026

Hydration

Гидратация

Hydration is how a frontend framework connects its JavaScript components to HTML the browser has already loaded. It reuses the existing page elements and makes them respond to application events.

What hydration does

Imagine a product page with a button that opens a size picker. The browser can display the button as soon as it receives the HTML, but the code that opens the picker isn't part of that markup. Hydration connects the JavaScript component to the button that's already on the page. This is different from the browser's built-in behavior: a plain link can navigate without any framework code.

From HTML to an interactive page

  1. A server renders the page to HTML, or a build step generates it ahead of time. The browser parses that HTML into the DOM, the tree of elements it uses to display the page.
  2. The client bundle loads and the framework runs the components with the initial data. It matches their output to the existing DOM and sets up event handling instead of creating every element from scratch.
  3. After that, changes to component state update the DOM through normal client rendering. A state update doesn't hydrate the component again.

A small React example

Assume the server renders Counter as <button>0</button> inside a container with the ID root. The browser runs this code using the same component:

import { useState } from 'react';
import { hydrateRoot } from 'react-dom/client';

function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(n => n + 1)}>{count}</button>;
}

hydrateRoot(document.getElementById('root'), <Counter />);

The first client render also expects a button showing 0, so React can reuse the existing button. Once the component is hydrated, clicking it increments the count. With an empty container, you'd use createRoot and render to mount the app instead.

Common failure: a hydration mismatch

The initial client render must agree with the DOM the browser built from the server HTML. For example, a timestamp formatted in the server's time zone may show a different time when the browser formats it during its first render. Start with the same formatted string on both sides, then switch to the user's time zone after hydration if needed. Invalid HTML nesting can also cause a mismatch: the browser may repair the markup before the framework sees it. React may regenerate the affected UI on the client, but you shouldn't rely on it to patch every difference.

Why it matters in practice and in interviews

Server rendering can make content appear sooner, but visible doesn't mean ready for input. Downloading JavaScript and running hydration still takes time, especially on slower devices. Some architectures reduce that work by hydrating only interactive regions and leaving the rest as plain HTML. In an interview, be ready to explain what each step delivers: SSR produces markup, the browser displays it, and hydration connects it to application behavior.