Install Preline UI with Hugo using Tailwind CSS
Install Preline UI with Tailwind CSS in Hugo projects, including JavaScript plugin setup, Hugo Pipes, static scripts, and optional dependencies.
Installation
Please note that the plugin has been tested with the 0.147.3 version of the framework. The framework was installed using the standard hugo new site <project-name> command.
If you are using your own project structure or a different version, pay attention to the file paths and features of your version!
Hugo quick setup
Start with a working Hugo site, then add Tailwind CSS before importing Preline UI.
Some components rely on third-party libraries. The setup below assumes full Preline UI usage with those dependencies preloaded. If you do not plan to use those components, you can remove the related libraries from your configuration.
-
Install Preline UI
Install
preline, then copy the package assets intostatic/prelineso Hugo can serve them.Terminalnpm install preline cp -r node_modules/preline static/prelinePreline UI uses the Tailwind CSS Forms plugin across form components. Install it if you have not already:
npm install -D @tailwindcss/forms -
Set up Tailwind CSS
Install Tailwind CSS and its PostCSS integration package.
Terminalnpm install tailwindcss @tailwindcss/postcssCreate a
tailwind.config.jsfile in the project root and include your Hugo layout, content, and asset paths.tailwind.config.js/** @type {import('tailwindcss').Config} */ module.exports = { content: [ './layouts/**/*.html', './content/**/*.md', './assets/**/*.js' ], theme: { extend: {} }, plugins: [] }; -
Set up PostCSS
Install PostCSS, the CLI, and Autoprefixer.
Terminalnpm install postcss postcss-cli autoprefixerCreate a
postcss.config.jsfile in the project root.postcss.config.jsmodule.exports = { plugins: { '@tailwindcss/postcss': {}, autoprefixer: {} } }; -
Include Preline CSS
Import Preline into
projects_root_directory/assets/css/main.css.main.css@import "tailwindcss"; @import "preline/variants.css"; @source "../../node_modules/preline/dist/*.js"; /* Optional Preline UI Datepicker Plugin */ /* @import "preline/src/plugins/datepicker/styles.css"; */ /* Third-party plugins */ /* @plugin "@tailwindcss/forms"; */ /* Preline Themes */ @import "./themes/theme.css";See the Theme docs to learn more about Preline Themes.
-
Run the Tailwind build
Run the Tailwind CSS build task.
Terminalnpx @tailwindcss/cli -i ./assets/css/main.min.css -o ./static/css/main.css --minify --watch -
Load scripts in the base layout
Add the stylesheet and script tags in
projects_root_directory/layouts/_default/baseof.html.baseof.htmlIf you use any optional third-party scripts, load them in
baseof.htmlbefore thePreline UIscript. Copy those files fromnode_modulesinto yourstatic/vendordirectory first.
Specific guide
Continue with a focused guide for wiring Preline UI JavaScript plugins into this framework.
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);