Tailwind CSS Range Slider Plugin API
Headless, unstyled range slider plugin built with JavaScript and TypeScript, including installation, usage, options, methods, events, and selectors.
Installation
To get started, install Range Slider plugin via npm, else you can skip this step if you are already using Preline UI as a package.
-
Install the plugin
Install
@preline/range-slidervia npmTerminalnpm i nouislider @preline/range-slider -
Add the plugin CSS
Use @source to register the plugin's JavaScript path for Tailwind CSS scanning, then @import the plugin's CSS files into your Tailwind CSS file.
main.css@import "tailwindcss"; /* @preline/range-slider */ /* [!code highlight:3] */ @source "../node_modules/@preline/range-slider/*.js"; @import "./node_modules/@preline/range-slider/variants.css"; @import "./node_modules/@preline/range-slider/theme.css"; -
Add the plugin JavaScript
Include the JavaScript
<script>that powers the interactive elements near the end of your</body>tag:HTML
Additional Initialization Options
Use the
non-autoentry if you need manual initialization. In this mode, automatic initialization on page load is not included, so the component should be initialized explicitly.HTML (non-auto)
Via bundler
When using a bundler (Vite, webpack, etc.), import the plugin directly as an ES module.
noUiSlideris referenced as a global — expose it onwindowbefore importing the plugin.JavaScript (auto)import * as noUiSlider from "nouislider"; window.noUiSlider = noUiSlider; import "@preline/range-slider";JavaScript (non-auto)import * as noUiSlider from "nouislider"; window.noUiSlider = noUiSlider; import HSRangeSlider from "@preline/range-slider/non-auto"; HSRangeSlider.autoInit(); // Or initialize a specific element manually const el = document.querySelector("#range-slider"); if (el) new HSRangeSlider(el);
Events
noUiSlider Events
Note that all events available in the noUiSlider plugin are also available in our plugin, just use el.noUiSLider to handle events.
When slider updates event example.
const { element } = HSRangeSlider.getInstance('#range-slider', true);
element.el.noUiSlider.on('update', (values) => {
console.log(element.formattedValue);
});
Ready to use Components
Looking for prebuilt UI components based on the Tailwind CSS? Preline UI packs hundreds of component examples for all your website needs.
Advanced Range Slider
Explore ready-to-use Tailwind CSS examples built with Preline UI.
View Advanced Range Slider examples