Contour Range Slider
Range slider whose track follows a curve — wave, ramp, steps, mountain or free path. Spring knob, tilted bubble. Native input, keyboard and touch ready.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Forms has 21 effects, including 2 free. Explore the category →
3 usage examples



How it works
A real <input type="range"> remains in the page beneath the SVG drawing: it keeps the value, form submission, input and change events, and all keyboard and screen reader interactions. The script positions it absolutely over the whole stage with opacity:0. On top it injects an SVG: it samples the curve into 256 segments with getPointAtLength, normalises the coordinates to 0–1, then draws the full track and fills the travelled portion with stroke-dasharray.
For a left-to-right monotone curve, the value maps to the horizontal axis (like a chart); for a free path with loops, it maps to arc length. The knob's target position (s.tu) is found by numerical inversion, then the actual position converges to it via a numerical spring (frequency ω, damping ζ) stepped at 4 ms intervals. The bubble tilts by the local slope, clamped through a hyperbolic tangent to ±0.6 rad, and straightens near the stage edges to avoid overflowing.
Each instance injects a private SVG containing a measuring path and gradient elements with randomly generated IDs — two copies on the same page never share SVG resources. The shape change lasts 0.7 s: each point of the old curve slides to its place on the new one, easing in and out. Without JavaScript, or if the script cannot start, the native <input type="range"> stays displayed as is and keeps its value. Under prefers-reduced-motion: reduce, all transitions are removed and positions are applied directly.
Accessibility
- Keyboard: the Left/Right arrows, Home, End and Page Up/Down keys are handled by the native field, the script does not intercept them. The focus ring only shows when arriving with the keyboard (
.srs-kbclass), never after a click. Before Chrome 86, Firefox 85 and Safari 15.4, it only shows at the first arrow key. - Screen reader: at each value, the script writes into
aria-valuetextthe short text of the bubble, the one fromdata-srs-format(in the demo: “42 km”). The long sentence fromdata-srs-output(“Break at km 42 · 1,180 m”) goes into the<output aria-live="polite">tag: it is displayed next to the label and announced when the value changes. - Touch: pointer events (
pointerdown,pointermove,pointerup) handle mouse, finger and stylus alike. For a monotone curve,touch-action: pan-yis set on the stage to leave vertical scrolling free; it is set tononefor free-path curves. - Reduced motion (
prefers-reduced-motion: reduce): all CSS transitions and the spring animation are disabled; the knob and bubble jump directly to their target position. - High contrast: the
.srs-hcclass orprefers-contrast: moreactivates a high-contrast theme (yellow #ffd400 accent on black). Windows Forced Colours mode (forced-colors: active) maps the track fill toHighlightand the knob toButtonFace/ButtonText.
Browser compatibility
The script needs ResizeObserver to know the size of the track: Chrome 64, Firefox 69, Safari 13.1. That is the real floor, above getPointAtLength, IntersectionObserver and Pointer Events. Two finishing touches need something newer: the focus ring as soon as the keyboard arrives (:focus-visible: Chrome 86, Firefox 85, Safari 15.4) and the spacing of the header and shape buttons (flex gap: Chrome 84, Safari 14.1). Versions read from @mdn/browser-compat-data.
Without JavaScript, or in a browser without ResizeObserver (the script then stops on an error), the native <input type="range"> field remains: no curve and no bubble, but a slider that works and sends its value.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0889-root">
<div class="srs-root srs-card" data-srs-shape="mountain">
<div class="srs-head">
<label class="srs-label">Slider label</label>
<output class="srs-out" aria-live="polite">Displayed value</output>
</div>
<div class="srs-stage">
<input class="srs-input" type="range" name="…" min="0" max="100" step="1" value="50" aria-label="…">
<!-- ContourRange.init() injects the SVG, knob (.srs-thumb) and bubble (.srs-bubble) here -->
</div>
<div class="srs-foot">
<div class="srs-chips" role="group" aria-label="Profile">
<button type="button" class="srs-chip" data-srs-shape-btn="wave" aria-pressed="false">Wave</button>
<button type="button" class="srs-chip" data-srs-shape-btn="mountain" aria-pressed="true">Pass</button>
</div>
<span class="srs-scale">Scale label</span>
</div>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
data-srs-shape on .srs-root |
wave |
Track shape: wave, ramp, steps, mountain, or a free SVG d path. setShape(d) via the API changes the shape at runtime with an animated transition. |
data-srs-format="{v} €" |
{v} |
Bubble text template: {v} = formatted slider value, {y} = data read from the vertical axis of the curve. Example: "{v} km · {y} m". |
data-srs-output="Up to {v} €" |
same as format | Sentence shown in <output aria-live> next to the label, and announced by screen readers when the value changes. It can say more than the bubble; aria-valuetext, for its part, repeats the bubble text. |
data-srs-y="450,1480,10" |
0,100 |
Range and rounding of the vertical data ({y}): minimum, maximum, rounding step. Without this attribute {y} stays between 0 and 100. |
data-srs-ticks="10" / data-srs-labels="20" |
no ticks | Tick marks perpendicular to the curve every 10 units; labels every 20 units. Pass 0 to remove ticks or labels. |
data-srs-area (boolean attribute) |
off | Chart mode: coloured area under the curve, horizontal axis, vertical guide line from the knob to the axis. Use when the curve height represents real data (altitude, price, temperature). |
--srs-accent / --srs-accent-2 |
#ff6a4d / #ffc247 |
Gradient colours on the filled track and knob gem. Set both CSS variables on .srs-root. |
--srs-h / --srs-top |
172px / 58px |
Total scene height and top padding reserved above the curve for the bubble. Increase --srs-top if the curve rises high and the bubble overflows. |
data-srs-demo (boolean attribute, not in the delivered code) |
off | Showcase walk: with no gesture from the visitor, the thumb changes value about every 2.3 s, then the track moves on to the next shape. It pauses on hover, during a drag or keyboard input, and does not play if the visitor asked for less motion. At each step the field receives an input event as if someone had set it: keep it for a presentation page, never in a form that records the value. |
Script control — ContourRange.get(element) |
— | Returns the controls of the slider carried by that .srs-root: setValue(v), setShape(d), setFormat(bubble, sentence), setTicks(step, numbers), setDemo(true), refresh(). ContourRange.init(container) starts sliders added after load. ContourRange is the only name set on window. |
FAQ
<input type="range"> is positioned absolutely over the whole stage with opacity:0: it stays in the accessibility tree, receives keyboard focus and triggers focus-visible. The script writes input.value directly during pointer drags and fires real input and change events so the page and forms receive them normally. The aria-valuetext attribute is updated with the formatted value at every move.data-srs-area turns the slider into an interactive mini-chart: it draws the coloured area under the curve, a horizontal reference axis, and a vertical guide from the knob to the axis. The bubble then shows the vertical axis value via {y} in the format template. Without this attribute the curve is purely decorative and none of these elements are drawn.data-srs-shape attribute (or setShape(d) via the API) accepts any SVG <path> d attribute. For a non-monotone path (loops, reversals), the script automatically switches to distance mode: the knob position tracks arc length rather than horizontal position. The native slider then travels from 0 to 100 % of the curve's total length.