Skip to content

Basic Slider

A copy-paste sliders & ranges component in pure HTML, CSS & vanilla JS. Zero dependencies, framework-agnostic, MIT-licensed.

Sliders & RangesHTMLJavaScriptCSSany framework

Copy into your project

HTML
<div class="nuda-slider-basic">
  <div class="nuda-slider-basic__track">
    <div class="nuda-slider-basic__fill" style="width:60%"></div>
    <div class="nuda-slider-basic__thumb" style="left:60%"></div>
  </div>
</div>
JavaScript
const track = document.querySelector('.nuda-slider-basic__track');
const fill  = track.querySelector('.nuda-slider-basic__fill');
const thumb = track.querySelector('.nuda-slider-basic__thumb');

let dragging = false;

const setPercent = (clientX) => {
  const rect = track.getBoundingClientRect();
  const pct = Math.min(100, Math.max(0, ((clientX - rect.left) / rect.width) * 100));
  fill.style.width = pct + '%';
  thumb.style.left = pct + '%';
};

thumb.addEventListener('pointerdown', () => (dragging = true));
window.addEventListener('pointerup', () => (dragging = false));
window.addEventListener('pointermove', (e) => dragging && setPercent(e.clientX));
track.addEventListener('click', (e) => setPercent(e.clientX));
CSS
.nuda-slider-basic {
  width: 100%;
  max-width: 220px;
  padding: 8px 12px;
}

.nuda-slider-basic__track {
  position: relative;
  height: 4px;
  background: rgba(255,255,255,.08);
  border-radius: 99px;
}

.nuda-slider-basic__fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: #e4ff54;
  border-radius: 99px;
  transition: width .35s cubic-bezier(.16,1,.3,1);
}

.nuda-slider-basic__thumb {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e4ff54;
  transform: translate(-50%,-50%);
  cursor: grab;
  box-shadow: 0 0 0 4px rgba(228,255,84,.15),0 0 12px rgba(228,255,84,.4);
  transition: left .35s cubic-bezier(.16,1,.3,1),transform .25s,box-shadow .25s;
}

.nuda-slider-basic__thumb:hover {
  transform: translate(-50%,-50%) scale(1.15);
  box-shadow: 0 0 0 6px rgba(228,255,84,.18),0 0 18px rgba(228,255,84,.6);
}

.nuda-slider-basic__thumb:active {
  cursor: grabbing;
}

How to use Basic Slider

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More sliders & ranges components

← Browse all NudaUI components