Skip to content
English
Glass lens slider comes with Pro. Its preview shows once you unlock it.

How it works

The thumb is a 64 × 40 pill scaled to 0.56 under a white cap. While it is held it springs to full size, the cap fades and the lens shows. The lens holds an exact copy of the track: the copy is shifted so that the point under the lens's centre lands on it, then scaled 1.45 × around that same point, so copy and track meet exactly at the centre and the lens magnifies everywhere, in every browser. In Chromium-based browsers (Chrome, Edge, Opera, Brave, Arc) the lens also goes through an SVG feDisplacementMap whose map is drawn for the pill shape on a canvas: deep inside nothing moves, and within the 10px rim band each point samples the picture up to 9px further in along the inward normal (the vertical part at a third of that, so the thin track is not dragged into an I shape at the round ends), so the fill bends and stretches where it meets the glass. Safari, Firefox and every other engine get the frosted lens instead: the same magnified copy with a 0.6px blur and a little more saturation. All of them share the lit rim (inset highlights, a specular streak and a faint ring of the secondary and tertiary colours). The position is a registered number: presses glide there, a drag writes it directly, and a release springs onto the nearest step.

Use it for

  • Controls that people hold and watch while they change something: brightness, volume, a colour temperature, a zoom level.
  • Media players, smart-home panels and camera or photo tools that want a tactile, current material.
  • Tracks that carry colour, such as a gradient to pick from, where the magnified picture under the lens helps aim.

Look elsewhere when

  • Picking a range with two ends: use the range slider.
  • Dense settings lists with many sliders, where every thumb turning to glass would be too much.

Usage

import { useState } from 'react'
import { GlassLensSlider } from './GlassLensSlider.jsx'

export function LampControls() {
  const [level, setLevel] = useState(72)
  const [warmth, setWarmth] = useState(70)
  return (
    <>
      <GlassLensSlider label="Brightness" value={level} onChange={setLevel} formatValue={(v) => `${v}%`} />
      <GlassLensSlider
        label="Warmth"
        value={warmth}
        onChange={setWarmth}
        track="linear-gradient(90deg, #bcd4f6, #fde8c4, #f59e3b)"
      />
    </>
  )
}

Props

PropTypeDefaultWhat it does
value / defaultValue / onChangenumber / number / (value) => void- / min / -The value, controlled or uncontrolled. onChange fires on every step while dragging.
onChangeEnd(value) => void—Fires once when a drag or press ends, and after each key press.
min / max / stepnumber / number / number0 / 100 / 1The range and the step. While dragging the thumb follows the pointer exactly; on release it springs onto the nearest step.
label / formatValuestring / (value) => string'Value' / StringAccessible name, and the value as read by screen readers (aria-valuetext).
trackstring—A CSS background for the whole track, such as a gradient of colours to choose from. When set, the fill is not drawn.
fillbooleantrueDraws the accent fill from the start of the track to the thumb.
marksnumber0Draws this many evenly spaced dots on the track; the lens magnifies them too.
refraction'auto' | 'soft''auto'auto bends the picture at the lens's rim with an SVG displacement filter in Chromium-based browsers and uses the frosted lens elsewhere; soft uses the frosted lens everywhere.
disabledbooleanfalseFades the slider and ignores input.
...restHTMLAttributes—Other attributes go to the root <div>.

Accessibility

  • The track is role="slider" with aria-valuemin, aria-valuemax, aria-valuenow and aria-valuetext from formatValue, named by label; the lens and its copy of the track are hidden from assistive tech.
  • Left and Down take a step away, Right and Up add one, PageUp and PageDown move a tenth of the range, Home and End go to the ends. Keys show the glass for a moment too. Focus shows a ring round the slider.
  • Touch: touch-action keeps vertical page scrolling; a finger takes the thumb once it moves sideways, and a tap without moving moves the thumb there.
  • The 44px tall control is the whole hit area, not only the thumb.
  • Reduced motion moves the thumb and the glass straight to their new state.

Motion

Glass in: the thumb and the magnification spring over 300ms on cubic-bezier(0.34, 1.45, 0.6, 1) while the cap fades over --ds-duration-fast; out is the same in reverse. Position: 420ms on cubic-bezier(0.3, 1.35, 0.5, 1), a small overshoot onto the step; while dragging it follows within 60ms.

Add it to your project

Pro members copy a prompt and their coding agent installs the source, the same way as the free components.

GlassLensSlider.jsxglass-lens-slider.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Form inputs
Availability grid comes with Pro. Its preview shows once you unlock it.
Boolean operations comes with Pro. Its preview shows once you unlock it.
Cascader comes with Pro. Its preview shows once you unlock it.