Skip to Content
Cristal

Forms

Slider

Picks a number in a range by dragging a thumb.

<cr-slider>CrSlider

Example

A slider suits values where the position in the range matters more than the exact number (volume, rough budget). For a precise value, prefer a text field of type number.

min (0 by default), max (100) and step (1) bound the value. A bubble follows the thumb showing the value, formatted for the page language, and grows while dragging or on keyboard focus; the filled part of the track follows the value.

Budget: €800

'use client';

import { useState } from 'react';
import { CrBox, CrSlider } from '@cristal-ui/react';

export default function SliderBasic() {
  const [budget, setBudget] = useState(800);

  return (
    <CrBox display="flex" direction="column" gap="lg" style={{ width: '100%', maxWidth: 360 }}>
      <CrSlider label="Volume" name="volume" value={40} />
      <CrSlider label="Maximum budget (€)" name="budget" min={0} max={2000} step={50} value={budget} onCrInput={(event) => setBudget(event.detail)} />
      <CrSlider label="Brightness (set by the system)" value={70} disabled />
      <p>Budget: €{budget.toLocaleString('en-US')}</p>
    </CrBox>
  );
}

In a form

The slider submits its value under its name. onCrInput reports every new value while dragging, onCrChange the final value, when the user releases the thumb.

If the user asked their system to reduce motion, the bubble changes size without transition.

Accessibility

  • Under the hood, a native input type="range": announced as "slider" with its value, set with the arrow keys, Page Up and Page Down, Home and End.
  • label is required and visible, linked to the slider.
  • The bubble repeats the value for the eyes only; screen readers read the native slider's value.
  • The track stands out from the background with a contrast of at least 3:1; keyboard focus draws an outline around the thumb.

API

Properties

PropertyTypeDefaultDescription
disabledbooleanfalseDésactive le curseur.
label (obligatoire)string—Libellé affiché au-dessus du curseur (obligatoire).
maxnumber100Valeur maximale.
minnumber0Valeur minimale.
namestring—Nom envoyé avec le formulaire.
stepnumber1Écart entre deux valeurs possibles.
valuenumber0Valeur choisie, ramenée entre min et max.

Events

Reactevent.detailDescription
onCrChangenumberÉmis quand l'utilisateur relâche la pastille ou change la valeur au clavier ; detail : la valeur.
onCrInputnumberÉmis pendant le glissement, à chaque nouvelle valeur ; detail : la valeur.

CSS parts

To style it from outside: cr-slider::part(name) { … }

PartDescription
bubbleLa bulle qui affiche la valeur.
controlLe curseur natif (input type="range").
labelLe libellé.

On this page