Install Preline UI with ASP.NET Core using Tailwind CSS
Install Preline UI with Tailwind CSS in ASP.NET Core projects, including JavaScript plugin setup, layout scripts, app styles, and optional dependencies.
Prerequisites
This guide assumes you have ASP.NET Core 9.0+ and .NET 9.0 SDK installed. You'll also need Node.js and npm for Tailwind CSS and Preline UI. If you haven't set up Tailwind CSS yet, check out the Tailwind CSS documentation first.
ASP.NET Core quick setup
Start with an ASP.NET Core project that already has Tailwind CSS configured, then add Preline UI and load its assets in your shared layout.
-
Install Preline UI
Install
prelinewith your preferred package manager in your ASP.NET Core 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.
The
datepicker/styles-utility.cssimport is required for the Datepicker component's calendar grid utility classes (.vc-*). Without it, Datepicker still initializes but its grid renders unstyled. -
Build CSS and add it to the layout
Build the Tailwind CSS output, then load the compiled stylesheet in
Views/Shared/_Layout.cshtml.Terminalnpx @tailwindcss/cli -i ./src/input.css -o ./wwwroot/css/tailwind.cssViews/Shared/_Layout.cshtmlDevelopment workflow: Run the build command whenever you change your styles. During development, you can use
npx @tailwindcss/cli -i ./src/input.css -o ./wwwroot/css/tailwind.css --watchto rebuild automatically.A separate terminal is easy to forget to start. To keep
tailwind.csscurrent automatically, wire the build into the project file instead sodotnet build,dotnet run, anddotnet watchregenerate it as part of the normal .NET build..csproj -
Serve the Preline UI runtime with LibMan
node_modulesis not served as static content fromwwwrootby default, so pull the compiled Preline JavaScript intowwwrootwith LibMan, the library manager built into the .NET tooling, then load it inViews/Shared/_Layout.cshtml.libman.json{ "version": "1.0", "defaultProvider": "jsdelivr", "libraries": [ { "library": "preline@latest", "destination": "wwwroot/lib/preline/", "files": ["dist/preline.js"] } ] }Terminallibman restoreViews/Shared/_Layout.cshtmlVisual Studio restores LibMan libraries on build automatically; on other tooling, run
libman restoreafternpm install. Thenpm installfrom step 1 is still required even when the runtime is served via LibMan — it is what providesvariants.cssandtheme.cssfor the Tailwind CSS build in the previous step.If a page uses a component with an optional third-party dependency, such as Datatable or Datepicker, place that page's own scripts in an
@section Scriptsblock positioned before thispreline.jstag in_Layout.cshtml— the default ASP.NET Core project templates render@RenderSectionAsync("Scripts")after the page's own scripts, which is the wrong order here. See optional dependencies for why the order matters.
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.