Run MAUI Blazor App in a Web Browser: Step-by-Step
In this article
Yes, you can run a .NET MAUI Blazor app in a web browser. A MAUI Blazor Hybrid app uses the same Razor components as a Blazor WebAssembly app, so you can add a web host project to the solution and run it in the browser without rewriting your UI. This is useful for quick previews, sharing a demo, or building a companion web version. You need the .NET SDK with the MAUI workload installed, plus a code editor such as Visual Studio or Visual Studio Code. The steps below use the .NET CLI and work on Windows, macOS, and Linux; menu labels can differ slightly by version and platform.
What You'll Need
- The .NET SDK (version 8 or later recommended) installed. Run
dotnet --versionin a terminal to check. - The .NET MAUI workload installed:
dotnet workload install maui. - An existing MAUI Blazor Hybrid project, or create one with
dotnet new maui-blazor. - A code editor (Visual Studio, Visual Studio Code, or any text editor).
- A modern browser such as Chrome, Edge, or Firefox.
Step-by-Step
- Open a terminal in your solution folder. Navigate to the folder that contains your
.slnfile or the project folder. - Create a new Blazor WebAssembly project. Run:
dotnet new blazorwasm -n MyApp.Web
This creates a standalone Blazor WebAssembly app namedMyApp.Web. You can name it anything you like. - Add the web project to your solution. Run:
dotnet sln add MyApp.Web/MyApp.Web.csproj
If you do not have a solution file, you can skip this and work directly with the project. - Reference your shared Razor components. If your MAUI Blazor app keeps its pages and components in a separate Razor Class Library (RCL), add a project reference from the web project to that library:
dotnet add MyApp.Web reference ../MyApp.Shared/MyApp.Shared.csproj
If your components live directly in the MAUI project, move them into a new Razor Class Library first, or copy the.razorfiles into the web project'sPagesfolder and adjust namespaces. The cleanest approach is a shared RCL used by both the MAUI app and the web app. - Update the web app's routing and layout. In the web project, open
App.razorand make sure theRoutercomponent points to your shared assembly. For example, addAdditionalAssemblies="typeof(SomeComponentInSharedLibrary).Assembly"to theRoutertag. Also copy or link yourMainLayout.razor,NavMenu.razor, and any CSS files into the web project so the UI looks the same. - Adjust any MAUI-specific code. Code that calls MAUI APIs such as
FileSystem,Preferences,SecureStorage, orConnectivitywill not compile or run in the browser. Wrap those calls in#if !WEBconditional compilation, or use dependency injection with a web-friendly implementation. Define aWEBconstant in the web project's.csprojunderif needed. - Build the web project. Run:
dotnet build MyApp.Web/MyApp.Web.csproj
Fix any compile errors that appear, usually from missing references or MAUI-only code. - Run the web app. Run:
dotnet run --project MyApp.Web/MyApp.Web.csproj
The terminal prints a local URL such ashttps://localhost:5001orhttp://localhost:5000. Open that URL in your browser. Your Blazor UI should load and behave like the MAUI version, minus native device features. - Test the main pages. Click through your navigation, submit forms, and check that data loading works. Because Blazor WebAssembly runs entirely in the browser, any server-side or native calls need a web-compatible replacement.
Common Mistakes
- Referencing the MAUI project directly from the web project. The MAUI project targets mobile and desktop platforms, not the browser. Share code through a Razor Class Library instead.
- Leaving MAUI-only APIs in shared components. Calls to
FileSystem,Preferences, orSecureStoragecompile in MAUI but fail in WebAssembly. Guard them with conditional compilation or abstract them behind an interface. - Forgetting to register services. If your components inject services, register them in the web project's
Program.csjust as you did inMauiProgram.cs. - Missing static assets. CSS, images, and fonts referenced from the MAUI project's
wwwrootmust also be present in the web project'swwwrootfolder. - Assuming native features work. Camera, GPS, file pickers, and notifications are not available in the browser through MAUI APIs. Use web equivalents or hide those features in the web build.
Tips
- Keep shared UI in a Razor Class Library from the start. Both the MAUI app and the web app then reference the same components, so changes appear in both.
- Use a compile constant such as
WEBto switch behaviour cleanly rather than scattering runtime checks. - Run the web project in watch mode with
dotnet watch --project MyApp.Webto reload on file changes. - If you only need a quick preview, consider a Blazor Web App with interactive server rendering instead of WebAssembly; it starts faster and avoids large download sizes.
- Test in the same browser you plan to demo in, and clear the cache after major CSS changes.
Troubleshooting
If the build fails with missing types, check that the shared library is referenced by both projects and that namespaces match. If the browser shows a blank page, open the developer tools console (F12) and look for errors; common causes are a missing index.html reference, a failed assembly load, or a JavaScript interop call that only exists in MAUI. If routing returns 404 on refresh, configure the web server to fall back to index.html; the built-in development server usually handles this, but static hosting may not. If the app loads but styles are broken, confirm the CSS files are in wwwroot and linked in index.html. If MAUI-specific code throws at runtime, search the shared components for platform APIs and replace them with web-safe alternatives or conditional compilation. Finally, run dotnet workload update and rebuild if you see SDK or workload version errors.
Frequently Asked Questions
Can I run my existing MAUI Blazor app in a browser without changes?
Not always. The Razor components can run, but any code that calls MAUI native APIs must be removed, guarded, or replaced with web-compatible code. Plan for some refactoring.
Do I need a separate project for the web version?
Yes. A Blazor WebAssembly project is the standard way to host the same components in a browser. Add it to the same solution and reference a shared Razor Class Library.
Will native features like the camera or file system work in the browser?
No. MAUI APIs for hardware and device storage are not available in WebAssembly. Use browser APIs through JavaScript interop or hide those features in the web build.
Can I use Blazor Server instead of WebAssembly?
Yes. A Blazor Web App with interactive server rendering can host the same components, provided the code does not depend on MAUI APIs. It requires a server connection but starts faster.
Why does my app show a blank page in the browser?
Usually a JavaScript error or a missing static file. Open the browser console for details, check that index.html and wwwroot assets are correct, and confirm the shared library is referenced.
Is this officially supported by Microsoft?
Blazor WebAssembly is a supported .NET web framework. Running MAUI Blazor components in the browser is a common pattern, but MAUI itself targets native platforms, so you are responsible for keeping shared code web-compatible.