Hydration helps Angular make a static page interactive by connecting the server-rendered HTML with Angular's code on the browser.
Hydration behavior in Angular
import { bootstrapApplication } from '@angular/platform-browser'; import { AppComponent } from './app/app.component'; bootstrapApplication(AppComponent, { providers: [], hydration: true });
The hydration: true option tells Angular to connect the server HTML with the client app.
This is used with Angular's standalone components and server-side rendering.
bootstrapApplication(AppComponent, { hydration: true });bootstrapApplication(AppComponent, { hydration: false });This Angular app shows a heading and a button. The button updates a counter when clicked. With hydration enabled, the server-rendered HTML is reused and Angular makes it interactive without reloading the content.
import { Component } from '@angular/core'; import { bootstrapApplication } from '@angular/platform-browser'; @Component({ selector: 'app-root', template: `<h1>Welcome to Hydrated Angular!</h1><button (click)="count = count + 1">Clicked {{count}} times</button>`, standalone: true }) export class AppComponent { count = 0; } bootstrapApplication(AppComponent, { hydration: true });
Hydration requires your app to be server-side rendered first.
If hydration is off, Angular will replace the server HTML, causing a flicker.
Hydration improves user experience by making pages interactive faster.
Hydration connects server HTML with Angular on the client.
It helps pages load faster and become interactive quickly.
Use hydration: true in bootstrapApplication to enable it.