Installation
Setting up Preline UI in an ASP.NET Core project using Tailwind CSS.
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.
Integrate Preline UI components with your ASP.NET Core MVC project using Tailwind CSS. This guide focuses on adding Preline UI to an ASP.NET Core project.
Install preline via npm or yarn.
npm install preline
Please note, Preline UI uses Tailwind CSS Forms plugin in all form components. Don't forget to install it, if you haven't done so already: npm install -D @tailwindcss/forms
Create Tailwind configuration and CSS file with Preline UI imports for your ASP.NET Core project.
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./Views/**/*.cshtml',
'./wwwroot/**/*.html',
'./wwwroot/**/*.js',
'./node_modules/preline/**/*.js'
],
theme: {
extend: {},
},
plugins: [],
};
@import "tailwindcss";
/* Preline UI */
@source "./node_modules/preline/dist/*.js";
@import "../node_modules/preline/variants.css";
/* Plugins */
@plugin "@tailwindcss/forms";
/* Preline Themes */
@import "./themes/theme.css";
Check out the Theme docs to learn more about Preline Themes.
Build Tailwind CSS and update your ASP.NET Core layout to include Preline CSS and JavaScript.
npx @tailwindcss/cli -i ./src/input.css -o ./wwwroot/css/tailwind.css
Development Workflow: Run the CSS build command whenever you make changes to your CSS. For development, you can use npx @tailwindcss/cli -i ./src/input.css -o ./wwwroot/css/tailwind.css --watch to watch for CSS changes.
Please note, Preline UI comes with some opinionated styles that are applied to components by default. If you want these styles in your project, you may include them into your CSS file. These styles used to come by default in Tailwind v3, so we decided to keep them 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);