Blazor · Foundations

Blazor Web App

Since .NET 8, one Blazor Web App template can mix static and interactive pages. Choosing the right render mode for each component is the key decision.

Beginner 5 min Lesson 3 of 31Examples target .NET 9 Blazor Web App.
0/31 in Blazor
On this page · 5 min · Beginner

Learning objectives#

  • Describe the four render modes
  • Apply a render mode to a component
  • Choose a mode for a given scenario
  • Understand what changes when a component becomes interactive

Explanation#

Static server-side rendering (Static SSR) renders HTML on the server and sends it to the browser. It is fast and SEO-friendly, but there is no interactivity — @onclick handlers do nothing. Enhanced navigation and streaming rendering still make it feel responsive.

Interactive Server renders on the server and keeps a SignalR (WebSocket) connection open. UI events travel to the server and DOM updates come back. It needs a constant connection and uses server memory per user.

Interactive WebAssembly downloads the .NET runtime and your app to the browser and runs it there. The first load is larger, but afterwards it works without a server connection.

Interactive Auto starts with Interactive Server for a fast first interaction, then switches to WebAssembly on later visits once the runtime is cached.

Visual explanation#

Blazor Web App render modes and where component code runsStaticSSRServer renders HTMLNo interactivity📄InteractiveServerRuns on serverEvents over SignalR🖥️InteractiveWebAssemblyRuns in browser.NET on WebAssembly🌐InteractiveAutoServer first, then browserBest of both⚡
The four Blazor Web App render modes and where component code runs.

Code example: A counter with an interactive render mode#

Razor / MarkupComponents/Pages/Counter.razor Illustrative
@page "/counter"
@rendermode InteractiveServer


<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>


@code {
    private int currentCount = 0;
    private void IncrementCount() => currentCount++;
}


@* Program.cs *@
@* builder.Services.AddRazorComponents()
       .AddInteractiveServerComponents()
       .AddInteractiveWebAssemblyComponents();
   app.MapRazorComponents<App>()
       .AddInteractiveServerRenderMode()
       .AddInteractiveWebAssemblyRenderMode()
       .AddAdditionalAssemblies(typeof(Client._Imports).Assembly); *@
Expected output
Each click increments the count. Remove @rendermode and the page still renders, but clicking does nothing (Static SSR).

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. @page "/counter" makes the component routable.
  2. @rendermode InteractiveServer makes this page interactive over SignalR.
  3. @onclick calls IncrementCount; Blazor re-renders the changed parts of the UI.
  4. Program.cs must register the interactive render modes you use.
  5. WebAssembly components must live in the .Client project so they can be downloaded to the browser.

Real-world use case#

A marketing or blog page: Static SSR. An internal admin dashboard on a fast network: Interactive Server. An offline-capable tool or heavy client-side UI: Interactive WebAssembly. A public app needing a fast first click: Interactive Auto.

Common mistakes#

Expecting @onclick to work in Static SSR

Static pages have no interactivity. Add a render mode, or use a standard HTML form post.

Calling the database directly from WebAssembly components

Code running in the browser cannot reach your database. Call an API with HttpClient.

Ignoring prerendering

Interactive components prerender by default, so OnInitializedAsync can run twice. Persist state with PersistentComponentState if needed.

Best practices#

  • Default to Static SSR and add interactivity only where needed
  • Apply render modes at the lowest component that needs them
  • Use an API for data access in WebAssembly components
  • Plan for SignalR reconnection with Interactive Server

Remember this#

One template, many render modes.

Static SSR by default; add @rendermode for interactivity.

Server = SignalR, WebAssembly = runs in browser, Auto = both.

Practice exercise#

Your task: Which render mode suits a public product listing page that must be fast and indexable, with no client-side interaction?

Show solution
Text Illustrative
Static SSR — no @rendermode. Add interactivity only to small components such as an “Add to cart” button.

Mini quiz#

Blazor Web App quizMultiple choice Question 1 of 2

Which render mode keeps a SignalR connection open?

Score so far: 0/0

Want more? Practise all Blazor MCQs · Blazor interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.