Install Preline UI with Blazor using Tailwind CSS
Install Preline UI with Tailwind CSS in Blazor projects, including JavaScript plugin setup, SPA navigation support, app scripts, and optional dependencies.
Prerequisites
This guide assumes you already have a Blazor project with Tailwind CSS configured. If you haven't set up Tailwind CSS yet, check out the Tailwind CSS documentation first.
Blazor quick setup
Start with a Blazor project that already has Tailwind CSS configured, then add Preline UI and wire it into your SPA navigation flow.
-
Install Preline UI
Install
prelinewith your preferred package manager in your Blazor project directory.Terminalnpm install prelinePreline UI uses the Tailwind CSS Forms plugin across form components. Install it if you have not already:
npm install -D @tailwindcss/forms -
Update Tailwind source CSS
Add the Preline UI CSS variants, forms plugin, and theme import to
src/input.css.src/input.css@import "tailwindcss"; @import "../node_modules/preline/variants.css"; @source "../node_modules/preline/dist/*.js"; /* Optional Preline UI Datepicker Plugin */ /* @import "../node_modules/preline/datepicker-styles-utility.css"; */ /* Plugins */ /* @plugin "@tailwindcss/forms"; */ /* Preline Themes */ @import "../node_modules/preline/theme.css"; /* Optional Preline UI Datatable Plugin: DataTables.net renders its own search/length/paging controls alongside Preline's own; hide the native ones since they can't be disabled through DataTables options alone. */ /* .dt-layout-row:has(.dt-search), .dt-layout-row:has(.dt-length), .dt-layout-row:has(.dt-paging) { display: none !important; } */Check out the Theme docs to learn more about Preline Themes.
-
Build CSS and copy Preline JavaScript
Build the Tailwind CSS output, then copy the Preline JavaScript file into
wwwroot/js.Terminalnpx @tailwindcss/cli -i ./src/input.css -o ./wwwroot/css/tailwind.css --minify mkdir -p wwwroot/js cp node_modules/preline/dist/preline.js wwwroot/js/Development workflow: a separate terminal command is easy to forget after editing styles or updating
node_modules. Wire both steps intopackage.jsonscripts, then run them automatically as part of the .NET build with an MSBuild target, sodotnet build,dotnet run, anddotnet watchalways regenerate current output.package.json{ "scripts": { "build:css": "tailwindcss -i ./src/input.css -o ./wwwroot/css/tailwind.css --minify", "copy:preline-js": "mkdir -p ./wwwroot/js && cp ./node_modules/preline/dist/preline.js ./wwwroot/js/preline.js", "build": "npm run copy:preline-js && npm run build:css" } }.csproj -
Load Preline UI in App.razor
Update
Components/App.razorto load Preline UI and re-runautoInitafter every enhanced navigation patch, not just the first page load — otherwise Preline UI stops initializing new markup after the first in-app navigation. See the Blazor guide for the Blazor Server and WebAssembly re-init pattern.Components/App.razor
Optional Preline UI styles
Preline UI ships with a small set of opinionated base styles. If you want them in your project, add them to your CSS file. These defaults used to come bundled with Tailwind CSS v3, so they are still available as an optional layer in Preline UI.
/* Adds pointer cursor to buttons */
@layer base {
button:not(:disabled),
[role="button"]:not(:disabled) {
cursor: pointer;
}
}
/* Defaults hover styles on all devices */
@custom-variant hover (&:hover);
Specific guide
Continue with a focused guide for wiring Preline UI JavaScript plugins into this framework.