Getting Started

TailwindBlazor integrates Tailwind CSS v4 into your Blazor app with zero external dependencies. No Node.js, no npm, no manual CLI installs.

Fastest

Use the project template

terminal
$ dotnet new install TailwindBlazor.Templates
$ dotnet new blazor-tailwind -n MyApp
$ cd MyApp && dotnet run

Everything pre-configured. Skip to Configuration to customize.

Options: --interactivity server|webassembly|auto|none and --Framework net8.0|net9.0|net10.0

Or add to an existing project

1. Install the package

terminal
$ dotnet add package TailwindBlazor

2. Create the CSS entry point

Create a file at Styles/app.css in your project root:

Styles/app.css
@import "tailwindcss";

3. Register the service

Add one line to your Program.cs:

Program.cs
using TailwindBlazor;

var builder = WebApplication.CreateBuilder(args);
builder.UseTailwind();

4. Reference the generated CSS

Add the stylesheet link in your App.razor or _Host.cshtml:

App.razor
<link rel="stylesheet" href="css/tailwind.css" />

5. Use Tailwind classes

Home.razor
<h1 class="text-3xl font-bold text-gray-900">
    Hello, TailwindBlazor!
</h1>

Configuration

TailwindBlazor works out of the box with sensible defaults. Everything is overridable through MSBuild properties, C# options, or appsettings.json.

MSBuild Properties

Set these in your .csproj to control build-time behavior:

.csproj
<PropertyGroup>
  <TailwindVersion>4.1.18</TailwindVersion>
  <TailwindInputFile>Styles/app.css</TailwindInputFile>
  <TailwindOutputFile>wwwroot/css/tailwind.css</TailwindOutputFile>
  <TailwindEnabled>true</TailwindEnabled>
  <TailwindMinify>false</TailwindMinify>
</PropertyGroup>
Property Default Description
TailwindVersion 4.1.18 Tailwind CLI version to download
TailwindInputFile Styles/app.css CSS entry point relative to project root
TailwindOutputFile wwwroot/css/tailwind.css Generated CSS output path
TailwindEnabled true Enable/disable the build target
TailwindMinify $(Optimize) Minify output (auto in Release)

C# Options

Configure the runtime hosted service via the UseTailwind overload:

Program.cs
builder.UseTailwind(options =>
{
    options.InputFile = "Styles/app.css";
    options.OutputFile = "wwwroot/css/tailwind.css";
    options.CliPath = "/custom/path/to/tailwindcss";
    options.TailwindVersion = "4.1.18";
});

appsettings.json

Options are also bound from the Tailwind configuration section:

appsettings.json
{
  "Tailwind": {
    "InputFile": "Styles/app.css",
    "OutputFile": "wwwroot/css/tailwind.css",
    "TailwindVersion": "4.1.18"
  }
}

How It Works

B At Build Time

MSBuild targets run before compilation:

  1. Detect your OS and CPU architecture
  2. Download the Tailwind CLI binary to ~/.tailwindblazor/cli/<version>/ (cached — only on first build)
  3. Run tailwindcss -i <input> -o <output> to generate the CSS
  4. In Release mode, --minify is applied automatically

D At Dev Time

When the environment is Development, the hosted service:

  1. Ensures the CLI is downloaded
  2. Starts tailwindcss --watch as a background process
  3. Streams CLI output to ILogger
  4. Kills the entire process tree on application shutdown

Build vs Runtime: MSBuild targets handle CSS generation for dotnet build and dotnet publish. The hosted service adds watch mode for live development. Both mechanisms work independently — you get CSS generation even without calling UseTailwind().

Supported Platforms

The correct CLI binary is resolved automatically based on your OS and CPU architecture.

Operating System Architecture CLI Binary
Windows x64 tailwindcss-windows-x64.exe
macOS x64 tailwindcss-macos-x64
macOS ARM64 tailwindcss-macos-arm64
Linux x64 tailwindcss-linux-x64
Linux ARM64 tailwindcss-linux-arm64

Troubleshooting

CLI download fails

Check your internet connection and firewall settings. The CLI is downloaded from github.com/tailwindlabs/tailwindcss/releases. You can also download it manually and set TailwindCliPath in your .csproj or options.CliPath in C#.

CSS is empty or missing classes

Tailwind v4 scans your project files automatically. Make sure your .razor files are in the project directory. If using a non-standard structure, check that the CLI can find your content files.

Watch mode not starting

The hosted service only runs when ASPNETCORE_ENVIRONMENT=Development. Make sure you're running with dotnet watch or dotnet run in development mode.

Want to disable Tailwind for a specific build?

Pass dotnet build -p:TailwindEnabled=false to skip CSS generation entirely.