This guide shows you how to set up Tailwind CSS for a new Blazor project using the same approach as the ShellUI CLI tool.
| Method | Setup Speed | Build Speed | Production Ready | Node.js Required |
|---|---|---|---|---|
| Play CDN | ⚡ Fastest (instant) | None | ❌ No | No |
| Standalone | Fast (one-time download) | Fast | ✅ Yes | No |
| npm | Medium (npm install) | Fast | ✅ Yes | Yes |
- Play CDN — Add one script tag, zero build step. Dev/demo only — serves full Tailwind (~500KB+), not optimized for production.
- Standalone — Downloads a single binary (~10MB) once. No Node.js. Recommended for Blazor — fast builds, production-ready.
- npm — Full Node.js workflow. Best if you already use npm or need plugins.
TL;DR: Standalone is the fastest production option for .NET/Blazor. Use CDN only for quick prototypes.
- .NET 9.0 SDK
- A Blazor project (new or existing)
The easiest way to set up Tailwind CSS in a Blazor project is using the ShellUI CLI tool, which handles everything automatically.
# Install globally
dotnet tool install -g ShellUI.CLI
# Or install from local source (if testing locally)
dotnet tool install -g ShellUI.CLI --add-source ./src/ShellUI.CLI/bin/Release# Navigate to your Blazor project
cd path/to/your/blazor-project
# Initialize ShellUI (this sets up Tailwind automatically)
dotnet shellui initThis command automatically:
- ✅ Downloads Tailwind CSS CLI (standalone, no Node.js required)
- ✅ Creates CSS files with design tokens
- ✅ Sets up MSBuild integration for auto-building
- ✅ Creates component folders
- ✅ Builds Tailwind CSS
# Add specific components
dotnet shellui add button input card
# List all available components
dotnet shellui listIf you prefer to set up Tailwind CSS manually or want to understand the process:
# Download Tailwind CLI (standalone, no Node.js required)
# Windows
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-windows-x64.exe
# Linux
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64
# macOS
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-x64
# Make executable (Linux/macOS)
chmod +x tailwindcss-*Create wwwroot/input.css:
@import "tailwindcss";Note: This creates a minimal Tailwind setup. Add your custom CSS variables, colors, and design tokens as needed.
Create wwwroot/app.css (placeholder, will be generated):
/* This file will be generated by Tailwind CSS */Create tailwind.config.js:
/** @type {import('tailwindcss').Config} */
export default {
content: [
'./Components/**/*.{razor,html,cshtml}',
'./Pages/**/*.{razor,html,cshtml}',
'./wwwroot/**/*.html',
],
darkMode: 'class',
theme: {
extend: {
colors: {
border: 'hsl(var(--border))',
input: 'hsl(var(--input))',
ring: 'hsl(var(--ring))',
background: 'hsl(var(--background))',
foreground: 'hsl(var(--foreground))',
primary: {
DEFAULT: 'hsl(var(--primary))',
foreground: 'hsl(var(--primary-foreground))',
},
secondary: {
DEFAULT: 'hsl(var(--secondary))',
foreground: 'hsl(var(--secondary-foreground))',
},
destructive: {
DEFAULT: 'hsl(var(--destructive))',
foreground: 'hsl(var(--destructive-foreground))',
},
muted: {
DEFAULT: 'hsl(var(--muted))',
foreground: 'hsl(var(--muted-foreground))',
},
accent: {
DEFAULT: 'hsl(var(--accent))',
foreground: 'hsl(var(--accent-foreground))',
},
popover: {
DEFAULT: 'hsl(var(--popover))',
foreground: 'hsl(var(--popover-foreground))',
},
card: {
DEFAULT: 'hsl(var(--card))',
foreground: 'hsl(var(--card-foreground))',
},
},
borderRadius: {
lg: 'var(--radius)',
md: 'calc(var(--radius) - 2px)',
sm: 'calc(var(--radius) - 4px)',
},
},
},
plugins: [],
}Create Build/ShellUI.targets:
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<ShellUIBinPath Condition="'$(ShellUIBinPath)' == ''">$(MSBuildProjectDirectory)\.shellui\bin</ShellUIBinPath>
<TailwindExecutable Condition="'$(OS)' == 'Windows_NT'">$(ShellUIBinPath)\tailwindcss.exe</TailwindExecutable>
<TailwindExecutable Condition="'$(OS)' != 'Windows_NT'">$(ShellUIBinPath)/tailwindcss</TailwindExecutable>
<TailwindInputCss Condition="'$(TailwindInputCss)' == ''">$(MSBuildProjectDirectory)\wwwroot\input.css</TailwindInputCss>
<TailwindOutputCss Condition="'$(TailwindOutputCss)' == ''">$(MSBuildProjectDirectory)\wwwroot\app.css</TailwindOutputCss>
<TailwindMinify Condition="'$(Configuration)' == 'Release'">--minify</TailwindMinify>
<TailwindMinify Condition="'$(Configuration)' != 'Release'"></TailwindMinify>
</PropertyGroup>
<Target Name="BuildTailwindCSS" BeforeTargets="BeforeBuild" Condition="Exists('$(TailwindExecutable)') AND Exists('$(TailwindInputCss)')">
<Message Importance="high" Text="Building Tailwind CSS..." />
<Exec Command=""$(TailwindExecutable)" -i "$(TailwindInputCss)" -o "$(TailwindOutputCss)" $(TailwindMinify)" />
<Message Importance="high" Text="Tailwind CSS built successfully!" />
</Target>
<Target Name="CleanTailwindCSS" AfterTargets="Clean" Condition="Exists('$(TailwindOutputCss)')">
<Message Importance="high" Text="Cleaning Tailwind CSS output..." />
<Delete Files="$(TailwindOutputCss)" />
</Target>
</Project>Add to your .csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<!-- ... existing content ... -->
<Import Project="Build\ShellUI.targets" />
</Project># Build CSS manually
./tailwindcss -i wwwroot/input.css -o wwwroot/app.css
# Or build the project (MSBuild will handle it automatically)
dotnet buildIn your MainLayout.razor or App.razor:
<link href="~/app.css" rel="stylesheet" />The fastest way to try Tailwind — no build step, no install. Add one script to your HTML:
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
</head>Pros: Instant setup, zero config.
Cons: Full Tailwind (~500KB+), no purging, not for production. Use for demos, prototypes, or Playground-style apps only.
For Blazor, add this to App.razor or your HTML host. Note: Design tokens (CSS variables) still need to be in your CSS for components to look correct.
If you prefer using npm and Node.js:
npm install -D tailwindcss
npx tailwindcss init/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./Components/**/*.{razor,html,cshtml}',
'./Pages/**/*.{razor,html,cshtml}',
'./wwwroot/**/*.html',
],
darkMode: 'class',
theme: {
extend: {
// ... same theme configuration as above
},
},
plugins: [],
}@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';Note: This creates a minimal Tailwind setup. Add your custom CSS variables, colors, and design tokens as needed.
npx tailwindcss -i wwwroot/input.css -o wwwroot/app.cssAfter setup, verify everything works:
-
Build the project:
dotnet build
-
Check for Tailwind CSS output:
wwwroot/app.cssshould contain generated CSS- Look for Tailwind utility classes in the output
-
Test in browser:
- Add some Tailwind classes to your components
- Verify they're styled correctly
-
Tailwind CSS not building:
- Check that
tailwind.config.jsexists - Verify content paths include your Razor files
- Ensure MSBuild targets are imported
- Check that
-
Styles not applying:
- Check that
app.cssis linked in your layout - Verify the CSS file is being generated
- Clear browser cache
- Check that
-
Build errors:
- Ensure Tailwind CLI is executable
- Check file paths in configuration
- Verify MSBuild targets syntax
- Check the Tailwind CSS documentation
- Review the ShellUI documentation
- Open an issue on GitHub
You can customize your theme similar to shadcn/ui. Copy theme configurations from tweakcn or similar tools and paste them into your wwwroot/input.css.
Example - Adding a custom theme:
- Visit tweakcn
- Customize colors, fonts, radius, etc.
- Copy the generated CSS
- Paste it into your
wwwroot/input.css(replace the existing:rootand.darksections)
To use custom fonts in your theme:
<!-- Add to your _Layout.cshtml or index.html -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Kode+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">Then update your input.css:
:root {
--font-sans: 'Kode Mono', ui-monospace, monospace;
/* ... other variables ... */
}/* Add to your input.css */
@import url('./fonts/kode-mono.css'); /* Your local font CSS */
:root {
--font-sans: 'Kode Mono', ui-monospace, monospace;
/* ... other variables ... */
}<!-- Add to your layout -->
<link href="https://cdn.jsdelivr.net/npm/@fontsource/kode-mono@5.0.0/index.css" rel="stylesheet">Always include fallbacks in your font definitions:
:root {
--font-sans: 'Custom Font', ui-sans-serif, system-ui, sans-serif;
--font-mono: 'Custom Mono', ui-monospace, 'SF Mono', monospace;
--font-serif: 'Custom Serif', ui-serif, serif;
}This ensures your design looks good even if the custom font fails to load.
Dark Theme with Custom Colors:
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 11.2%;
/* ... customize all colors ... */
}
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 11.2%;
/* ... dark mode colors ... */
}Custom Border Radius:
:root {
--radius: 0.75rem; /* More rounded */
}Custom Shadows:
:root {
--shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}Once Tailwind CSS is set up:
- Add ShellUI components (if using ShellUI) using
dotnet shellui add - Customize the design system in
input.css(use tweakcn for themes!) - Install custom fonts for the perfect look
- Build your Blazor app with beautiful components
- Deploy using your preferred hosting solution
Happy coding! 🚀