Install Preline UI with Remix using Tailwind CSS
Install Preline UI with Tailwind CSS in Remix projects, including JavaScript plugin setup, route rescans, client effects, and optional dependencies.
Installation
Please note that the plugin has been tested with the 2.16.2 version of the framework. The framework was installed using the standard npx create-remix@latest <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!
Remix quick setup
If Tailwind CSS is not set up yet, start with the official Remix + Tailwind CSS guide first.
-
Install Preline UI
Install
prelinewith your preferred package manager.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 -
Include Preline CSS
Import Preline into
projects_root_directory/app/tailwind.css.tailwind.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"; */ /* Plugins */ /* @plugin "@tailwindcss/forms"; */ /* Preline Themes */ @import "./themes/theme.css";See the Theme docs to learn more about Preline Themes.
-
Add type definitions for Preline
Create a
global.d.tsfile for the shared window typings, for exampleprojects_root_directory/app/global.d.ts.global.d.tsimport type { IStaticMethods } from "preline/dist"; declare global { interface Window { // Optional third-party libraries _; $: typeof import("jquery"); jQuery: typeof import("jquery"); DataTable; Dropzone; noUiSlider; VanillaCalendarPro; // Preline UI HSStaticMethods: IStaticMethods; } } export {}; -
Add Preline UI to the root layout
Import the required external libraries and initialize Preline UI in
projects_root_directory/app/root.tsx.root.tsximport { useEffect } from "react"; import { ... Outlet, useLocation, } from "@remix-run/react"; ... import "./tailwind.css"; // Optional third-party libraries if (typeof window !== 'undefined') { Promise.all([ import('jquery'), import('lodash'), import('nouislider'), import('datatables.net'), import('dropzone/dist/dropzone-min.js'), import('vanilla-calendar-pro') ]).then(([$, _, noUiSlider, , , VanillaCalendarPro]) => { window._ = _.default; window.$ = $.default; window.jQuery = $.default; window.DataTable = $.default.fn.dataTable; window.noUiSlider = noUiSlider.default; window.VanillaCalendarPro = VanillaCalendarPro; }).catch(error => { console.error('Failed to initialize dependencies:', error); }); } ... export function Layout({ children }: { children: React.ReactNode }) { const location = useLocation(); // Preline UI useEffect(() => { let mounted = true; const initPreline = async () => { try { if (typeof window !== 'undefined' && mounted) { await import('preline/dist'); if (window.HSStaticMethods && mounted) window.HSStaticMethods.autoInit(); } } catch (error) { console.error('Failed to initialize Preline:', error); } }; initPreline(); return () => { mounted = false; }; }, [location.pathname]); return ( <html lang="en"> <head> ... </head> <body> ... {children} ... </body> </html> ); } export default function App() { return <Outlet />; }
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.
Community workarounds
Explore community-shared fixes, examples, and integration tips for edge cases that come up while using Preline UI.