FormsPremium

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.

SVG + JSSliderFormAccessible

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

Trail planner — rest stop on an elevation profile — Contour Range Slider example 1

① Trail planner — rest stop on an elevation profile

WhenPreparation dashboard for a trail run or mountain bike outing, as the main element of a stage section.
WhyThe curved track, chart mode and bubble showing exact altitude at the chosen point turn the slider into a topographic map reader — users see and choose in a single gesture.
SettingsShape mountain, data-srs-area enabled, data-srs-y="450,1480,10" (altitude min/max/rounding), format {v} km, phrase Break at km {v} · {y} m. Shape-switching chip buttons. In the capture, the mouse clicks the profile twice: the thumb slides there.
Number of guests in a caterer's quote — the total is recalculated under the slider — Contour Range Slider example 2

② Number of guests in a caterer's quote — the total is recalculated under the slider

WhenSecond step of an online quote: the customer says how many people the order is for. The track rises as a ramp from 20 to 200 guests, on a light card; the chosen menu and the estimated total are written just below.
WhyA ramp says “the further right, the bigger” before the figures are even read. The total changing at each value answers the customer's only question at this step, and saves typing a number then submitting to see a price.
Settingsramp shape, light theme (.srs-light with .srs-card), min="20" max="200" step="5", format {v} guests, ticks every 20, numbered every 40, accent #b4532a. The total is computed by the page, which listens to the field's input event. In the capture, the mouse clicks the track twice.
Audio studio — reverb level in a mix panel — Contour Range Slider example 3

③ Audio studio — reverb level in a mix panel

WhenSettings panel in an online audio or video creation tool (DAW, editor, studio).
WhyThe wave shape makes the control expressive and differentiates the interface from a plain horizontal slider. The bubble tilted with the slope adds depth. Arrow-key control is natural for this type of tool.
Settingswave shape, format {v}%, ticks every 25 without numbers, no chart mode. Main colour --srs-accent: #a78bfa (purple), height --srs-h: 148px to fit the panel. In the capture, one mouse click sends the thumb from 45 to 76%.

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-kb class), 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-valuetext the short text of the bubble, the one from data-srs-format (in the demo: “42 km”). The long sentence from data-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-y is set on the stage to leave vertical scrolling free; it is set to none for 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-hc class or prefers-contrast: more activates a high-contrast theme (yellow #ffd400 accent on black). Windows Forced Colours mode (forced-colors: active) maps the track fill to Highlight and the knob to ButtonFace / 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.

Chrome 64+✓ Full from version 86 (measured on Chromium 149); from 64 to 85, the two finishing touches are missing
Firefox 69+✓ Full from version 85 (measured on Firefox 151)
Safari 13.1+✓ Full from 15.4 in the WebKit 26.5 test build; real Safari not verified
Edge 79+✓ Not verified (same engine as Chrome)
iOS 13.4+✓ Not verified on a real phone (simulated tap: the value follows the finger)
Android Chrome 64+✓ Not verified on a real phone (simulated tap: the value follows the finger)

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):

index.html — structure
<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 / propertyDefaultEffect
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

The <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.
When the curve height represents real data (altitude, price, temperature…), 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.
Yes. The 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.