Internative Logo

What Is Blazor? Building Interactive Web UIs with C# and .NET

What Is Blazor? Building Interactive Web UIs with C# and .NET

A company that runs on .NET often ends up with two teams and two languages: C# on the server and JavaScript or TypeScript in the browser. Validation rules, data models and business logic get written twice, and every change has to cross the boundary between them. Blazor is Microsoft's answer for those teams: a web UI framework that lets you build interactive pages with C# and Razor components, and share the same code between the server and the client.

This article explains what Blazor is, how its render modes work, where it fits, when a JavaScript framework is the better choice, and how it compares with the alternatives.

What is Blazor?

Blazor is an open-source front-end web framework that is part of ASP.NET Core. You build the interface from Razor components, files that mix HTML markup with C#, and Blazor runs them either on the server or in the browser through WebAssembly. It can also host the same components inside native desktop and mobile apps.

Blazor started as an experiment by Steve Sanderson, who showed a prototype at NDC Oslo in 2017. Microsoft's ASP.NET team announced it as an experimental project in February 2018 and published the first preview, 0.1.0, on 22 March 2018. The server-side model, Blazor Server, became the first supported release with .NET Core 3.0 on 23 September 2019. Blazor WebAssembly, which runs .NET in the browser, followed as a fully supported release, 3.2.0, on 19 May 2020.

The biggest change came with .NET 8, which merged the two models into one project type, the Blazor Web App. A single app can now render pages statically on the server, make some components interactive over a server connection and run others in the browser, choosing per component or per page.

How Blazor works

Razor components. A component is a .razor file with markup and a @code block. It holds state, handles events and can be nested and reused. Components render into an in-memory tree, and Blazor works out the smallest set of changes to apply to the page when state changes.

Render modes. Since .NET 8, each component or page can use one of four modes:

  • Static server rendering: HTML is produced on the server and sent to the browser, with no interactivity. This is fast and suits content pages and forms.
  • Interactive Server: the component runs on the server and the browser receives UI updates over a real-time SignalR connection.
  • Interactive WebAssembly: the .NET runtime and the app's code are downloaded to the browser and run there, client-side.
  • Interactive Auto: the component starts on the server and switches to WebAssembly on later visits, once the files have been downloaded.

JavaScript interop. Blazor can call JavaScript and JavaScript can call back into C#. That is how Blazor apps use browser APIs and existing JavaScript libraries such as charts or maps.

Blazor Hybrid. In a native app built with .NET MAUI, WPF or Windows Forms, Razor components run in the .NET process and render into an embedded web view. WebAssembly is not involved, and the app has full access to the device.

Key features

  • C# across the stack: share models, validation and business logic between server and client.
  • Component model with parameters, events, layouts, forms and validation built in.
  • Flexible rendering: static, server-interactive, WebAssembly and auto modes in one app.
  • Prerendering and streaming rendering, so the first view arrives quickly even when data is slow.
  • Full .NET ecosystem: NuGet packages, dependency injection, Entity Framework Core on the server and familiar tooling in Visual Studio and VS Code.
  • Offline-capable apps: a standalone Blazor WebAssembly app can be deployed as static files and run as a Progressive Web App.
  • Hybrid apps for desktop and mobile with the same components.

Where Blazor is used

  • Line-of-business applications: internal tools, back-office systems and approval workflows built by .NET teams.
  • Admin panels and dashboards on top of existing ASP.NET Core APIs.
  • Enterprise portals where strong typing and long-term maintainability matter more than the newest front-end trend.
  • Modernising older ASP.NET Web Forms or MVC applications while keeping the team in C#.
  • Desktop and mobile apps that share a UI with a web version through Blazor Hybrid.

When to choose Blazor, and when not to

Choose Blazor when:

  • Your team works in C# and .NET, and you want one language and one set of models from database to screen.
  • The application is data-heavy and behind a login: forms, grids, workflows and reports.
  • You need to share validation and business rules between server and client.
  • You plan to run the same UI on the web and in a desktop or mobile app.

Look elsewhere when:

  • The product is a public, content-heavy site where search ranking and first-load speed drive results. A JavaScript framework such as Next.js has a longer track record there.
  • Your front-end team already works in React or Vue and has its component libraries in place.
  • First-visit download size is critical on slow networks. The WebAssembly mode downloads a .NET runtime, which is larger than a typical JavaScript bundle; server or static rendering avoids that.
  • The app needs many users on unreliable connections in Interactive Server mode. Each user holds a live connection and state on the server, so dropped connections and server memory need planning.

Blazor and its alternatives

OptionLanguageWhere the UI runsBest fit
BlazorC#Server, browser (WebAssembly) or native app.NET teams, business applications
ASP.NET Core MVC / Razor PagesC#Server-rendered HTMLClassic server-rendered sites
React / Next.jsJavaScript / TypeScriptBrowser, with server renderingPublic products, large front-end ecosystem
AngularTypeScriptBrowserLarge single-page apps in TypeScript teams
Vue / NuxtJavaScript / TypeScriptBrowser, with server renderingTeams that want a lighter learning curve

A frequent question is how Blazor relates to Razor. Razor is the syntax that mixes C# with HTML; it is used both by ASP.NET Core MVC views and Razor Pages, which render HTML on the server per request, and by Blazor components, which keep state and stay interactive. In practice, MVC and Razor Pages suit document-style sites, and Blazor suits application-style screens.

Against React or Angular, the decision is mostly about the team. Blazor removes the language boundary for .NET developers; JavaScript frameworks offer a larger ecosystem, more component libraries and a bigger hiring pool. If the backend choice is still open, our guide to choosing a backend stack: NestJS, Express or .NET covers the server side of the same decision.

How we use Blazor at Internative

We use Blazor on projects that benefit from a unified .NET stack and shared business logic. It is especially effective for enterprise applications that need strong typing, long-term maintainability and integration with the Microsoft ecosystem, often on top of an ASP.NET Core backend.

If you are planning a business application on .NET, our enterprise software team can help you decide whether Blazor or a JavaScript front end fits it better.

Frequently asked questions

What is the difference between Blazor and Razor?

Razor is a syntax for combining HTML with C#. Blazor is a framework that uses Razor to build components that hold state and respond to user events. Razor views and Razor Pages render HTML once per request on the server, while Blazor components can stay interactive on the server or in the browser.

Is Blazor as good as React?

They solve the same problem for different teams. React has the larger ecosystem, more third-party components and a bigger talent pool. Blazor lets .NET teams build interactive UIs in C# and share code with the backend. For a .NET-centred business application, Blazor is often the more productive choice; for a public product with a JavaScript team, React usually is.

Is Blazor still relevant?

Yes. Blazor is part of ASP.NET Core and ships with each .NET release. The .NET 8 unification into the Blazor Web App, with static, server and WebAssembly rendering in one model, made it a full-stack framework rather than two separate hosting options.

Is Blazor free?

Yes. Blazor is open source as part of ASP.NET Core and can be used in commercial applications without licence fees. Costs come from hosting and the team's time, as with any web framework.

Related services

Where this topic becomes an engagement.

Keep reading

The articles that follow this one.