Bruno DelorenceBruno
Appearance
Appearance

Choose your reading theme.

Contact

Split slider

A value slider whose dark fill carries its label and value, and whose handle parts around the text it meets.

split-slider/split-slider.tsx
Live · interactive

The live component, numbered part by part. Every measurement is read from it as it is drawn. Point at a row to outline its part, or at a part to find its row.

The choices it offers, each value drawn live and the default marked, with how to pick one.

When to use

  • Tuning one number by feel, where the effect shows as it moves: blur, radius, opacity, zoom.
  • Stacks of settings in an editor or an inspector, where each row needs its name and its value and little else.
  • Bounded ranges with a fixed step, from min to max, read with their unit: 76 px, 58%, −1.5 °C.
  • Narrow panels: the label and the value live inside the bar, so a row costs only its height.

When not to use

  • Values that must be typed exactly, or ranges too wide to drag to one number. Use a number field, or pair one with the slider.
  • A low and a high bound at once. Use a range slider with two thumbs.
  • A few named steps, like Low, Medium, High. A segmented control or a stepped slider names them.
  • Long labels: the label and the value share one bar, so keep the label to a word or two.
  • Settings that apply only on Save, where nothing changes as it moves: the drag gives no feedback worth having.

Live feedback

The slider is for settings whose effect shows as it moves. onChange fires on every step, while dragging and from the keys, so apply each value as it comes.

  • Let the slider hold its own value with defaultValue, or hold it in the parent with value and onChange.
  • There is no separate “done” event: if applying a value is slow, keep the preview cheap and save later, not on every step.
  • Each step ticks once the reader has pressed or keyed the slider; set sound={false} where clicks would be out of place.

Ranges and steps

  • Choose min, max and step for the effect, not for round numbers: 0 to 100 px in ones for a blur, −10 to 10 °C in halves for an alert.
  • Keys move by step, Shift or Page Up and Down by ten of it, Home and End to the ends. Every value snaps to the step.
  • The fill always grows from the left end, below zero too. Nothing marks zero in a signed range, so name the setting so the sign is clear.
  • Keep the range draggable: a few hundred steps at most across the bar. Past that, a pixel of drag skips values.

Stacks

Several sliders in a column share a width and a height, so their values start at the same place and line up down the stack. Leave a small gap between rows; the bar needs no border or title of its own.

Each one drawn with the component itself, used well or badly.

The label and the value share one bar, so every word has to earn its place.

  • A noun for the label, in sentence case: Blur, not Adjust blur or BLUR. It is also the slider’s name for screen readers.
  • A short symbol for the unit: px, %, °C, ms. These are spoken as pixels, percent, degrees Celsius; spell out any other in unitName, and its singular in unitNameOne.
  • Steps that need no more than one decimal: 1.5 °C reads in a glance, 1.4999 doesn’t.
  • Negative values are drawn with a true minus sign on their own; pass plain numbers.

You can add this component with the shadcn CLI or by hand:

Into components/split-slider of any React project, with no setup:

Terminal
npx shadcn@latest add https://brunodelorence.com/r/split-slider.json

Either way it needs React 19 and a bundler that supports CSS Modules, such as Next.js or Vite. It has a dark colour scheme: it follows your page’s color-scheme, light unless the page sets one, or its colorScheme prop, with nothing to configure. Browsers without light-dark() show it light.

Usage

blur-control.tsx
import { useState } from 'react';import { SplitSlider, SplitSliderDemo } from './split-slider';// One slider in your own panel.export function BlurControl() {  const [blur, setBlur] = useState(76);  return <SplitSlider label="Blur" value={blur} onChange={setBlur} unit="px" unitName="pixels" />;}// Or the stage of three, without its demo.export function SliderStage() {  return <SplitSliderDemo autoplay={false} />;}

Each state below is a live instance, locked so you can study it.

The pieces it is built from, each with its measurements read live.

Below are variations of this component, each live, with its code.

Below zero

A frost alert from −10 to 10 °C in half degrees, with a true minus sign below zero.

Coarse steps

A wide zoom slider from 25 to 200% in steps of 25: the fill follows the pointer and settles on the nearest step when let go.

Compact

Smaller sliders, 44 px high, for a dense brush panel, with the ticks turned off.

Colour mixer

Hue, saturation and lightness held by the parent, mixing the swatch above as they move.

A slider for a tool’s panel: a dark, rounded fill grows over a light track, with a thin white handle near its end. Where the fill covers the label or the value they turn white, and when the handle reaches one of them it parts into two dots above and below the text. Drag it past an end and it stretches like a rubber band; every step ticks with a soft synthesised click.

  • The slider is drawn twice: its label, value and handle once in dark on the light track, and once in white on top, clipped with clip-path to the fill’s rounded shape. Wherever the fill reaches, the text turns white, down to half a letter.
  • The fill’s end, its stretch past either end and a slight thinning are CSS variables. A spring integrated each frame moves them toward the value and stops once it settles, so React renders only when the value changes.
  • The handle is two halves, each a short bar seen through a clip-path. Near the label or the value the clips shrink to dots at their outer ends: the handle splits a little ahead of a text in the direction it travels, and closes as soon as it is past. The texts’ places are measured once, and again when the slider or its font changes.
  • Dragged past an end, the slider stretches along a rubber-band curve that gives less and less, up to a third of its height; let go, a lightly damped spring brings it back with a small wobble.
  • Each step ticks with a click made by the Web Audio API: a short sine that drops in pitch over a burst of filtered noise, lower and quieter as the value falls. One AudioContext serves the page; it is created on the reader’s first press or key, suspended when the ticks stop and closed with the last slider.
  • Every colour is a light-dark() pair on the root, so the slider takes the page’s color-scheme, or the colorScheme prop. The pairs sit in @supports, where builds that rewrite light-dark() leave them as written, so a page that sets no color-scheme stays light, and so do browsers without light-dark(). At night the fill is a lit grey over a dark grey track.
PropTypeDefaultDescription
labelstring—The visible label, which also names the slider for screen readers. Required.
valuenumber—The value, when the parent holds it (with onChange).
defaultValuenumber50The value to start from when the slider holds its own.
onChange(value: number) => void—Called with each new value, as it is dragged or stepped.
minnumber0The lowest value.
maxnumber100The highest value.
stepnumber1The step of a drag and of the arrow keys; Page Up and Page Down take ten.
unitstring'px'Shown after the value; a percent sign sits against the number.
unitNamestring'pixels'The unit as screen readers say it: “76 pixels”.
soundbooleantrueTicks on each step, once the reader has pressed or keyed the slider.
heightnumber58Its height in px; its text, corners and handle scale with it.
refRef<SplitSliderHandle>—Drives the slider as a pointer would (press, drag, release); the demo uses it.
colorScheme'light' | 'dark' | 'system'—Its colours: light, dark, or the reader’s system setting. Without it the component follows the page’s color-scheme, which is light unless the page sets one.
classNamestring—Extra class for the slider’s root.
autoplaybooleantrueOn SplitSliderDemo, the stage of three sliders (which takes className too): while on screen and untouched, a ghost pointer drags the sliders now and then.

Name, role and value

The whole bar is one role="slider" named by its label, with aria-valuemin, aria-valuemax, aria-valuenow and an aria-valuetext of the value and unitName: “76 pixels”. The two drawn copies of the text are hidden, so the value is heard once (WCAG 4.1.2, Name, Role, Value).

  • Unset, unitName is named from unit: px is pixels, % percent, ° degrees, ms milliseconds. A symbol it doesn’t know is read as written, and an empty unit adds no name, so the value is heard alone.
  • A value of one takes the singular, “1 pixel”; for a custom unitName, set unitNameOne too.

Keyboard

  • Tab reaches the bar; the arrow keys step, Shift with an arrow or Page Up and Down take ten steps, Home and End go to the ends (WCAG 2.1.1, Keyboard).
  • The focus ring is a 2 px outline 3 px off the bar, following its rounded shape (WCAG 2.4.7, Focus visible).

Pointer and touch

  • A tap or a click anywhere on the bar brings the fill there, so no drag is needed (WCAG 2.5.7, Dragging movements).
  • The whole bar is the target: at 44 px high it is well above the 24 × 24 px minimum (WCAG 2.5.8, Target size).
  • On a touch screen only a sideways move drags; a vertical swipe still scrolls the page.

Contrast

The label and the value meet 4.5:1 on the track and on the fill, in light and dark (WCAG 1.4.3, Contrast (minimum)). The white handle stands out from the fill at well over 3:1.

Motion and sound

Under reduced motion there is no spring and no stretch: the fill moves straight to its value. The click is never the only feedback, and plays only after the reader’s own press or key.

In this build

  • Each slider is a role="slider" named by its label, with aria-valuenow and an aria-valuetext that speaks its unit (“76 pixels”). The two drawn copies of the text and the handle are aria-hidden, so the value is heard once.
  • The arrow keys step (Shift for ten steps), Page Up and Page Down take ten, Home and End go to the ends, and the focus ring follows the slider’s rounded shape.
  • The click is never the only feedback. It starts only after the reader’s own press or key, never plays for the demo, and the mute button (a toggle with aria-pressed) silences it.
  • On a phone a vertical swipe still scrolls the page. Under reduced motion there is no demo, no spring and no stretch: the fill moves straight to its value.

The complete source behind this demo. Open source under the MIT license, © 2026 Bruno Delorence: copy it, change it, ship it.

split-slider.tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import {  useEffect,  useImperativeHandle,  useLayoutEffect,  useRef,  useState,  type CSSProperties,  type FocusEvent,  type KeyboardEvent,  type PointerEvent,  type Ref,} from 'react';import { clickSound, type ClickSound } from './click-sound';import { GhostPointer, runDemo, type Point } from './ghost-pointer';import { useAutoplay } from './use-autoplay';import styles from './split-slider.module.css';/* * Split slider: a value slider whose dark fill carries its label, a thin handle and, as it grows, * its value.
split-slider.module.css
/* Split slider (split-slider.tsx). Its proportions follow its height, --h (the height prop sets it   inline). The component writes where the fill is as it moves: --p (its end, 0 to 1 of the width),   --over and --under (how far it is stretched past the right or the left end, in px) and --squash   (how much a stretch thins it). --handle-inset and --handle-start come from the component's   GEOMETRY. *//* The palette, on both roots (the slider and the demo's stage). Each colour is a light-dark() pair,   so it follows the color-scheme in force: the page's, or the one the colorScheme prop sets. The   pairs sit in @supports, where a build step that rewrites light-dark() for older browsers leaves   them as written: rewritten, they would need a color-scheme the same step had rewritten too, and   on a page that sets none every colour would drop. Without light-dark(), the light colours stay. */.stage,.slider {  --surface: #fff;  --surface-2: #eee;  --hover: #f2f2f4;  --line: rgb(0 0 0 / 0.06);  --ink: #111;  --ink-muted: #6b6b6b;  --icon: #8e8e93;  --icon-hover: #3a3a3c;  --accent: #303030;  --accent-2: #141414;  --accent-ink: #fff;
click-sound.ts
/* * The slider's click: a soft, short tick synthesised with the Web Audio API, no audio file. Each * tick is a sine blip that drops in pitch, over a breath of filtered noise for its edge, shaped by * an envelope a few milliseconds long. Higher values tick higher and louder. * * Browsers allow sound only after a gesture of the reader's, so nothing plays before their first * press or key on a slider. One AudioContext serves every slider on the page: it is created on * that first gesture, suspended when the ticks stop (an idle context still runs its audio thread), * and closed when the last slider is gone. *//** A tick's length, in seconds. */const LENGTH = 0.05;/** Ticks closer than this (ms) are skipped: a fast drag would buzz. */const MIN_GAP = 22;/** After this long without a tick (ms), the audio is suspended. */const REST = 1500;let context: AudioContext | null = null;let noise: AudioBuffer | null = null;let users = 0;let lastTick = 0;let restTimer = 0;
ghost-pointer.tsx
'use client';import type { CSSProperties, Ref } from 'react';/* * The demo's ghost pointer, and the timeline that moves it. A demo is a script of awaited steps: * wait, glide the pointer somewhere, press, drag, let go. A glide is a curved flight played by the * Web Animations API; a drag runs frame by frame, so that the script can move a slider along with * the pointer. Stopping the demo (the reader takes over, or it scrolls away) ends the step in * progress at once: its promise rejects, which ends the script right there, and the pointer fades * out. */export type Point = { x: number; y: number };export type Demo = {  /** Resolves after `ms`. */  wait: (ms: number) => Promise<void>;  /** Glides the pointer to `to`, in the stage's own px. */  moveTo: (to: Point) => Promise<void>;  /** Presses and holds: the arrow dips. */  press: () => Promise<void>;  /** Drags to `to` over `ms`, eased, handing each point on the way to `each`. */  drag: (to: Point, ms: number, each: (point: Point) => void) => Promise<void>;
use-autoplay.ts
'use client';import { useCallback, useEffect, useRef, useState } from 'react';/* * When a demo may play on its own: while part of it is on screen and the tab is visible, never * under reduced motion, and not while the reader is using it. `take()` hands it to the reader; it * takes back over `idle` ms after their last input. */export function useAutoplay<T extends HTMLElement>(idle = 6000) {  const ref = useRef<T>(null);  const [visible, setVisible] = useState(false);  const [reduced, setReduced] = useState(true);  const [taken, setTaken] = useState(false);  const timer = useRef(0);  useEffect(() => {    const element = ref.current;    if (!element) return;    let onScreen = false;    const update = () => setVisible(onScreen && !document.hidden);    const observer = new IntersectionObserver(      ([entry]) => {        onScreen = entry.isIntersecting;