Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 41 ยท Getting Started

What Is Blazor?

Learn what Blazor is, how it lets you build interactive web UIs in C# instead of JavaScript, how components work, and how it compares with React, Angular and Razor Pages in .NET 10.

Blazor is a web UI framework from Microsoft that lets you build interactive pages with C# and HTML instead of JavaScript. You write small, reusable pieces called components, each one a mix of markup and C# code. Blazor takes care of turning them into a page, updating the page when your data changes, and wiring up clicks and typing to your C# methods.

If you already know C# and a little HTML, Blazor lets you use one language for the screen, the logic and often the server too. In this track you will learn components, Razor syntax, binding, forms, routing, state, JavaScript interop, authentication and hosting. This first lesson explains the big picture before any setup.

Blazor itself needs the .NET SDK and a browser or server host, so the examples on this site cannot run the real framework. Real Blazor code is shown in read-only blocks, and the runnable examples are small, clearly labelled C# stand-ins that demonstrate the underlying ideas (render trees, parameters, events, validation) on a real .NET runtime.

The core idea: components

Everything in Blazor is a component. A page is a component, a button you reuse is a component, and the whole app is a component that contains the others. A component is a .razor file:

HTML
<h1>Hello, @Name!</h1>
<button @onclick="Greet">Say hello</button>

@code {
    [Parameter] public string Name { get; set; } = "world";

    private void Greet() => Console.WriteLine("Hello from C#");
}

Three things to notice. Markup is ordinary HTML. @Name inserts a C# value. The @code block holds normal C# members: fields, properties and methods. The file name (Greeting.razor) becomes the component's class name, so you can use it elsewhere as <Greeting Name="Ada" />.

What Blazor does at runtime

Conceptually, Blazor repeats a loop:

  1. A component renders: its markup becomes a small tree of elements and text called the render tree.
  2. The user does something (click, type, submit). Blazor calls your C# event handler.
  3. After the handler finishes, the component renders again. Blazor compares the new tree to the old one and computes the minimal set of changes.
  4. Only those changes are applied to the real page (the DOM).
flowchart LR
  A["Component state"] --> B["Render tree"]
  B --> C["Diff against previous tree"]
  C --> D["Apply minimal DOM updates"]
  D --> E["User event (click, input)"]
  E --> F["Your C# handler changes state"]
  F --> A

The Blazor render loop: state produces a tree, the diff updates the page, events change state.

You never touch the DOM yourself. You change state, and the screen follows.

A runnable stand-in for the render loop

Here is the loop in plain C#. A Component has state and a BuildMarkup method. Dispatch simulates an event: it runs a handler and then re-renders, printing only when the markup changed. This is not Blazor's code, just the idea.

C# Stand-in: state in, markup out

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

The first Render shows Count: 0; each click changes the state, which changes the markup, which is the only thing sent to the "DOM". The final Render finds nothing new. The real framework does the same, with a much finer-grained diff.

Why use Blazor?

  • One language. C# on the client and the server, with static typing, generics, LINQ, async/await and the whole .NET library.
  • Shared code. Validation rules, models and helpers can be the same type on both sides.
  • Components all the way down. Composition, parameters, layouts and routing follow a consistent model.
  • Great tooling. Visual Studio, Rider and VS Code give IntelliSense, refactoring and debugging inside .razor files.
  • Free and open source, part of ASP.NET Core and supported by Microsoft.

Where Blazor runs

Blazor has several render modes, which decide where your component code executes:

Mode Where C# runs How the page updates
Static server rendering Server, once per request Plain HTML, no live connection
Interactive Server Server A SignalR connection sends UI diffs to the browser
Interactive WebAssembly In the browser .NET runs on WebAssembly, no round trip
Interactive Auto Server first, then browser Starts fast, then switches to WebAssembly

In modern .NET (8 and later) a single app can mix these modes per component. Chapter 8 covers them in depth; for now just know that the components you write look the same in every mode.

Blazor compared with other tools

Blazor React / Angular Razor Pages / MVC
Language C# JavaScript / TypeScript C#
Style Component-based Component-based Page or controller per request
Interactivity Built in Built in Needs JavaScript
Runs in the browser Via WebAssembly (optional) Yes No (server HTML)

Blazor is not a replacement for knowing the web. You still write HTML and CSS, and you can call JavaScript when you need a browser API. But for apps with rich interaction, such as dashboards, admin tools, forms and internal systems, it lets a C# team move quickly. If you want the server-side companion, see the ASP.NET track.

What you will need

  • The .NET 10 SDK (the dotnet command-line tool).
  • An editor: Visual Studio, Visual Studio Code with the C# Dev Kit, or Rider.
  • A modern browser.

The next lesson walks through creating your first project and what each file in it does.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the basic building block of a Blazor app?

    Pages, layouts and reusable widgets are all components: a mix of markup and C# in a .razor file.
  2. 2. What happens after your event handler finishes?

    Blazor re-renders the component, diffs the new render tree with the old one and updates only what changed.
  3. 3. Which statement about render modes is correct?

    Interactive Server, WebAssembly and Auto decide where the component code executes; the components themselves look the same.
  4. 4. Which tool does Blazor NOT require for ordinary UI logic?

    You can build interactive UI in C# alone. JavaScript is only needed for browser APIs that .NET does not wrap.

Summary

  • Blazor builds interactive web UI with C# and HTML using components.
  • A component renders a tree; after each event it renders again and only the differences reach the page.
  • Render modes decide where components run: server, browser (WebAssembly) or both.
  • You still use HTML and CSS, and can call JavaScript when needed.
  • The examples here are stand-ins; the real framework needs the .NET SDK.

Next: Setting Up and Project Structure