Effort Slider Free React component
A stepped slider in a clean little card, the kind AI apps use for "effort" or "quality" settings. The thumb follows your finger, then snaps to the nearest step with a springy bounce while the label rolls to the new value. Full keyboard support.
Get the code
npx shadcn@latest add https://alphenex.com/r/effort-slider.jsonWorks with any React project through the shadcn CLI. Prefer to paste it yourself? Copy the two files below into components/alphenex/. No Tailwind or animation library needed.
import EffortSlider from '@/components/alphenex/effort-slider';
<EffortSlider steps={['Low', 'Medium', 'High', 'Max']} />'use client';
import { useCallback, useEffect, useRef, useState } from 'react';
import './effort-slider.css';
/**
* EffortSlider
* A stepped slider in a small card: drag or tap anywhere on the track, the
* thumb follows your finger, then snaps to the nearest step with a springy
* bounce while the label above rolls to the new value.
*
* Free from Alphenex Lab: https://alphenex.com/lab/effort-slider (MIT)
*/
export default function EffortSlider({
label = 'Effort',
steps = ['Low', 'Medium', 'High', 'Max'],
defaultIndex = 1,
recommended = 1, // index marked "Recommended", or -1 for none
minLabel = 'Faster',
maxLabel = 'Smarter',
accent = '#111418',
onChange,
className = '',
style,
...props
}) {
const [index, setIndex] = useState(defaultIndex);
const [drag, setDrag] = useState(null); // 0–1 while dragging, else null
const trackRef = useRef(null);
const last = steps.length - 1;
useEffect(() => setIndex(Math.min(defaultIndex, last)), [defaultIndex, last]);
const commit = useCallback(
(next) => {
const clamped = Math.max(0, Math.min(last, next));
setIndex(clamped);
onChange?.(clamped, steps[clamped]);
},
[last, onChange, steps],
);
const ratioAt = (clientX) => {
const rect = trackRef.current.getBoundingClientRect();
return Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
};
const onPointerDown = (e) => {
e.currentTarget.setPointerCapture(e.pointerId);
setDrag(ratioAt(e.clientX));
};
const onPointerMove = (e) => {
if (drag !== null) setDrag(ratioAt(e.clientX));
};
const onPointerUp = () => {
if (drag === null) return;
commit(Math.round(drag * last));
setDrag(null);
};
const onKeyDown = (e) => {
if (e.key === 'ArrowRight' || e.key === 'ArrowUp') commit(index + 1);
else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') commit(index - 1);
else if (e.key === 'Home') commit(0);
else if (e.key === 'End') commit(last);
else return;
e.preventDefault();
};
const ratio = drag ?? index / last;
const live = drag !== null ? Math.round(drag * last) : index;
return (
<div className={`alx-effort ${className}`} style={{ '--alx-effort-accent': accent, ...style }} {...props}>
<div className="alx-effort__head">
<span>{label}</span>
<strong key={live} className="alx-effort__value">
{steps[live]}
</strong>
</div>
<div className="alx-effort__ends" aria-hidden="true">
<span>{minLabel}</span>
<span>{maxLabel}</span>
</div>
<div
ref={trackRef}
className={`alx-effort__track ${drag !== null ? 'is-dragging' : ''}`}
role="slider"
tabIndex={0}
aria-label={label}
aria-valuemin={0}
aria-valuemax={last}
aria-valuenow={index}
aria-valuetext={steps[index]}
onPointerDown={onPointerDown}
onPointerMove={onPointerMove}
onPointerUp={onPointerUp}
onPointerCancel={onPointerUp}
onKeyDown={onKeyDown}
style={{ '--alx-effort-ratio': ratio }}
>
<span className="alx-effort__rail" />
<span className="alx-effort__fill" />
{steps.map((step, i) => (
<span key={step} className={`alx-effort__tick ${i <= live ? 'is-on' : ''}`} style={{ left: `${(i / last) * 100}%` }} />
))}
<span className="alx-effort__thumb" />
</div>
{recommended >= 0 && (
<div className="alx-effort__rec" style={{ left: `calc(20px + ${recommended / last} * (100% - 40px))` }} aria-hidden="true">
Recommended
</div>
)}
</div>
);
}
/* EffortSlider, Alphenex Lab (MIT) */
.alx-effort {
--alx-effort-accent: #111418;
position: relative;
width: min(340px, 100%);
padding: 18px 20px 34px;
border-radius: 20px;
background: #fff;
box-shadow: 0 1px 0 rgba(17, 20, 24, 0.04), 0 24px 50px -24px rgba(17, 20, 24, 0.35);
color: #111418;
font-size: 13px;
}
.alx-effort__head {
display: flex;
gap: 8px;
align-items: baseline;
color: #6b7280;
}
.alx-effort__value {
color: #111418;
font-weight: 600;
animation: alx-effort-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes alx-effort-in {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: none; }
}
.alx-effort__ends {
display: flex;
justify-content: space-between;
margin: 18px 0 10px;
color: #9ca3af;
font-size: 11px;
}
.alx-effort__track {
position: relative;
height: 22px;
cursor: pointer;
touch-action: none;
outline: none;
}
.alx-effort__rail,
.alx-effort__fill {
position: absolute;
top: 50%;
left: 0;
height: 4px;
border-radius: 99px;
transform: translateY(-50%);
}
.alx-effort__rail {
right: 0;
background: #eceef1;
}
.alx-effort__fill {
width: calc(var(--alx-effort-ratio) * 100%);
background: var(--alx-effort-accent);
}
.alx-effort__tick {
position: absolute;
top: 50%;
width: 4px;
height: 4px;
border-radius: 50%;
background: #cfd3d9;
transform: translate(-50%, -50%);
transition: background 0.2s ease;
}
.alx-effort__tick.is-on {
background: #fff;
}
.alx-effort__thumb {
position: absolute;
top: 50%;
left: calc(var(--alx-effort-ratio) * 100%);
width: 20px;
height: 20px;
border-radius: 50%;
background: #fff;
box-shadow: 0 0 0 1px rgba(17, 20, 24, 0.08), 0 4px 12px rgba(17, 20, 24, 0.22);
transform: translate(-50%, -50%);
}
/* Snap with a little bounce; follow the finger instantly while dragging. */
.alx-effort__track:not(.is-dragging) .alx-effort__thumb,
.alx-effort__track:not(.is-dragging) .alx-effort__fill {
transition: left 0.45s cubic-bezier(0.3, 1.5, 0.5, 1), width 0.45s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.alx-effort__track.is-dragging .alx-effort__thumb {
transform: translate(-50%, -50%) scale(1.15);
}
.alx-effort__track:focus-visible .alx-effort__thumb {
box-shadow: 0 0 0 3px rgba(10, 143, 208, 0.35), 0 4px 12px rgba(17, 20, 24, 0.22);
}
.alx-effort__rec {
position: absolute;
bottom: 12px;
color: #9ca3af;
font-size: 10px;
transform: translateX(-50%);
white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
.alx-effort__value { animation: none; }
.alx-effort__track .alx-effort__thumb,
.alx-effort__track .alx-effort__fill { transition: none !important; }
}
Paste this into Claude, ChatGPT, Cursor, Lovable or v0 to build it from scratch.
Build a React "EffortSlider" with plain CSS: a white rounded card with a label ("Effort") and the current step name, end labels ("Faster" / "Smarter"), and a track with a dot for each step. While dragging (pointer capture), the thumb and fill follow the pointer exactly; on release, snap to the nearest step with a CSS transition using an overshooting cubic-bezier(0.3, 1.5, 0.5, 1). Animate the step name in with a short slide-up keyframe whenever it changes. Mark one step "Recommended" under the track. Use role="slider" with aria-valuenow/valuetext and support arrow keys, Home and End. Props: label, steps, defaultIndex, recommended, minLabel, maxLabel, accent, onChange.How the effort slider works
The thumb and fill are positioned from one CSS variable: the ratio from 0 to 1 along the track. While you drag, the ratio follows the pointer exactly and transitions are switched off.
On release the ratio jumps to the nearest step, and the transitions switch back on with an overshooting curve, which is what makes the thumb bounce into place. The step name re-mounts with a short slide-up animation.
It is a real slider for assistive technology: role="slider", the current step as aria-valuetext, and arrow keys, Home and End all work.
Frequently asked questions
Want motion like this on your website?
We design and build custom websites with motion, 3D and SEO built in. Websites from $500.