Installation
How to install dependencies and structure your app.
Choose the setup that matches your starting point.
New Project
You need the .NET 10 SDK. Nothing else: no Node.js, npm or package.json.
Create a Blazor app
Components need interactivity. Create a Blazor Web App with interactive server rendering:
dotnet new blazor -n MyApp --interactivity Server --all-interactiveRun the init command
From the app's folder, run init to set up Tailwind, the theme and the usings:
Add components
You can now start adding components to your project.
The command above adds the Button component to Components/UI/Button. You can then use it in a page:
@page "/"
<Button>Click me</Button>Run your app
dotnet watchTailwind builds with your project, and recompiles as you edit while dotnet watch runs.
Existing Project
Run init in the folder of your Blazor app (or pass --project). It changes your project like this, and every change is a plain file you can read and edit:
- Adds
Tailwind.targetsand imports it in your.csproj. Tailwind now builds with your project, using the standalone Tailwind CLI, which is downloaded on the first build. - Adds
TailwindWatcher.csand one line inProgram.cs. In development, Tailwind recompiles as you edit, so hot reload shows new classes. - Moves your existing
wwwroot/app.csstoStyles/site.cssand imports it, so none of your styles are lost. - Adds
Styles/theme.css: the design tokens. See Theming. - Adds
Styles/Vendor/tw-animate.cssandStyles/Vendor/variants.css, the animation utilities and variants the components use. - Adds a global using for
Blazix.Primitivesto your.csproj, and an@usingfor your components to_Imports.razorwhen you add the first component. - Adds the
Blazix.Primitivespackage, at the same version as the CLI. - Writes
blazix.json, which records your namespace, components folder and what you've installed.
Then add components with add, as above.
If your app has a .Client project (the WebAssembly and Auto render modes), run init in either project,
or in the solution folder above them. The components, usings, package and blazix.json go in the .Client
project, so pages in every render mode can use them. Tailwind and TailwindWatcher.cs go in the server project, which
serves the CSS and scans the .Client project's files with @source. The server project gets the usings too,
for its layouts and static pages. add and list also work from any of these folders. See
Render Modes.
A standalone WebAssembly app has no server to run the watcher, so init leaves it out and links app.css in wwwroot/index.html.
The CSS is recompiled on each build.
init asks for Inter and falls back to the system font. To get Inter, load it in App.razor's <head>. The comment at the top of Styles/theme.css shows how.
Render Modes
The components work in Interactive Server, Interactive WebAssembly and Interactive Auto apps, prerendered or not. In static server rendering, they render but don't respond: menus, dialogs and the rest need an interactive render mode.
Interactive Auto runs a page on the server the first time, while the WebAssembly runtime downloads, and in the browser once it's cached, usually from the next full page load. Nothing changes in how you use the components. To set up an Auto app:
dotnet new blazor -n MyApp --interactivity AutoRun init in the MyApp folder the template made. Then keep these in mind:
- Components that use Blazix go in the
.Clientproject, whereaddputs the components. The server can run them, but WebAssembly can only load what's in the client. - Give them a render mode. Without
--all-interactive, the layout in the server project renders statically, so put@rendermode InteractiveAutoon each page, or render an interactive part of the layout (a header with a menu) as its own component:<Header @rendermode="InteractiveAuto" />. - Register services in both
Program.csfiles. A page runs on the server (prerendering, and Auto before WebAssembly) and in the browser, so a service it injects, like theToastManager, must be registered in both. Otherwise the page fails only once it runs in the browser.addtells you when one is missing. - Cascading values stop at a render mode. A
DirectionProviderorToasterin a static layout doesn't reach an interactive page. Put theToasterin an interactive part of the layout (<Toaster @rendermode="InteractiveAuto" />) or in the page. For right-to-left, cascade the direction from bothProgram.csfiles instead:builder.Services.AddCascadingValue(_ => TextDirection.Rtl);. With--all-interactivethe layout is interactive, and both work there as usual.
Parts of a page can run on different runtimes, for example a header on the server over a page on WebAssembly. That works:
Escape, outside presses and modal dialogs see popups from both runtimes, and the ids they render can't collide. But each
runtime has its own services, so a toast added on one runtime doesn't show in a Toaster on the other.
Interactive Auto keeps the parts of a page on one runtime, so this only comes up when you mix fixed render modes.
Icons
The components draw their icons with the Icon component from Blazix.Icons. add
installs the package of the set they use: Lucide
(Blazix.Icons.Lucide) unless you pick another set with init --icon-library. For icons of your
own, add the set's package too. See Icons.
The examples in these docs use Blazix.Icons.Lucide (<Icon Data="LucideIcons.ChevronRight" />). To
copy them as they are, add the package and @using Blazix.Icons and @using Blazix.Icons.Lucide to
_Imports.razor.