Overview
noUiSlider is a lightweight range slider with multi-touch support and a ton of features. It supports non-linear ranges,
requires no external dependencies, has keyboard support, and it works great in responsive designs.
For full documentation please check the
plugin's site .
Basic
Basic example of range slider with full touch support.
copy
<div class="mb-0">
<label class="form-label">Example</label>
<div id="basicSlider"></div>
<div class="pt-5">
<div class="fw-semibold mb-2">Min: <span id="basicSliderMin"></span></div>
<div class="fw-semibold mb-2">Max: <span id="basicSliderMax"></span></div>
</div>
</div>
// Initialize the component and set up event listeners.
const slider = document.getElementById('basicSlider');
const valueMin = document.getElementById('basicSliderMin');
const valueMax = document.getElementById('basicSliderMax');
noUiSlider.create(slider, {
start: [20, 80],
connect: true,
range: {
min: 0,
max: 100
}
});
slider.noUiSlider.on('update', (values, handle) => {
if (handle)
valueMax.innerHTML = values[handle];
else
valueMin.innerHTML = values[handle];
});
Sizes
Change the sliders default size by applying custom size classes .noUi-sm
and .noUi-lg
.
copy
<div id="smallSlider" class="noUi-sm"></div>
<div id="normalSizeSlider"></div>
<div id="largeSlider" class="noUi-lg"></div>
Vertical
Example of horizontal range slider.
copy
<div id="verticalSlider"></div>
// Initialize the component and set up event listeners.
const slider = document.getElementById('verticalSlider');
noUiSlider.create(slider, {
start: [60, 160],
connect: true,
orientation: 'vertical',
range: {
min: 0,
max: 200
}
});
noUiSlider can provide a basic tooltip using the tooltips option.
Soft Limits
If you want to disable the edges of a slider, the set event can be used to reset the value if a limit is passed.
copy
<div id="softLimitsSlider"></div>
// Initialize the component and set up event listeners.
const slider = document.getElementById('softLimitsSlider');
noUiSlider.create(slider, {
start: [50],
range: {
min: 0,
max: 100
},
pips: {
mode: 'values',
values: [20, 80],
density: 4
}
});