Slider
A slider allows a user to select one or more values within a range
Usage
import { Slider } from '@heroui/react';Anatomy
import { Slider, Label } from '@heroui/react';
export default () => (
<Slider step={10}>
<Label />
<Slider.Output />
<Slider.Track>
<Slider.Fill />
<Slider.Steps />
<Slider.Thumb />
</Slider.Track>
<Slider.Marks>
<Slider.Mark value={0} />
<Slider.Mark value={50} />
<Slider.Mark value={100} />
</Slider.Marks>
</Slider>
)Slider.Steps and Slider.Marks are optional. Compose them independently as needed.
Examples
Steps
Place Slider.Steps inside Slider.Track to display a dot at each increment defined by minValue, maxValue, and step. The step prop controls value increments even without visible dots.
Dots start at minValue. If maxValue is not on a step, no extra dot is added at that endpoint. Invalid ranges and ranges requiring more than 1,000 dots omit the indicators.
Marks
Place Slider.Marks directly after Slider.Track as a sibling, and add Slider.Mark children with a required value. Each label is positioned at its value, so marks can be unevenly spaced and do not need to match the step increments.
Use children for custom labels. Without children, a mark displays its value using the slider's locale and formatOptions. Marks outside the slider's bounds, or with non-finite values, are not rendered. Marks are labels; they do not change the value or snapping behavior.
Steps and Marks
Combine dots and labels independently. Fractional steps are supported; this example uses step={0.1} with labels at 0, 0.5, and 1.
Range with Steps and Marks
For a single thumb, dots and marks from the minimum through the selected value receive data-filled="true". For a range, only those between the first and last thumbs receive it, including the endpoints.
Vertical Steps and Marks
Dots and labels follow orientation="vertical" automatically. Give vertical sliders a container with a defined height. Horizontal indicators also follow the locale's right-to-left direction.
Disabled
Range Slider Anatomy
import { Slider, Label } from '@heroui/react';
export default () => (
<Slider defaultValue={[25, 75]}>
<Label />
<Slider.Output />
<Slider.Track>
{({state}) => (
<>
<Slider.Fill />
{state.values.map((_, i) => (
<Slider.Thumb key={i} index={i} />
))}
</>
)}
</Slider.Track>
</Slider>
)Vertical
Range
Controlled Value
Control the value with value and onChange.
Custom Value Formatting
Use formatOptions to format the displayed value. This example formats it as USD.
Custom Output
Customize Slider.Output to control how the selected values are shown.
Render Function
Customization
Tailwind CSS
Global CSS
To customize the Slider component classes, you can use the @layer components directive.
Learn more.
@layer components {
.slider {
@apply gap-2;
}
.slider__output {
@apply text-sm text-muted;
}
.slider__track {
@apply relative h-2 w-full rounded-full bg-surface-secondary;
}
.slider__fill {
@apply absolute h-full rounded-full bg-accent;
}
.slider__thumb {
@apply size-4 rounded-full bg-accent border-2 border-background;
}
}Styling Reference
HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
CSS Classes
The Slider component uses these CSS classes (View source styles):
Base Classes
.slider- Base slider container.slider__output- Output element displaying current value(s).slider__track- Track element containing fill, optional step dots, and thumbs.slider__fill- Fill element showing selected range.slider__thumb- Individual thumb element.slider__steps- Decorative step indicator container inside the track.slider__step- Individual step dot.slider__marks- Mark label container after the track.slider__mark- Individual value-positioned label
State Classes
.slider[data-disabled="true"]- Disabled slider state.slider[data-orientation="vertical"]- Vertical orientation.slider__thumb[data-dragging="true"]- Thumb being dragged.slider__thumb[data-focus-visible="true"]- Thumb keyboard focused.slider__thumb[data-disabled="true"]- Disabled thumb state.slider__track[data-fill-start="true"]- Fill starts at beginning.slider__track[data-fill-end="true"]- Fill ends at end.slider__step[data-filled="true"]- Step dot within the selected interval.slider__mark[data-filled="true"]- Mark label within the selected interval
Indicator Data Attributes
| Attribute | Applies to | Description |
|---|---|---|
data-slot | Steps, step dots, marks, mark labels | slider-steps, slider-step, slider-marks, and slider-mark, respectively |
data-value | Step dots and mark labels | The numeric value represented by the indicator |
data-filled="true" | Step dots and mark labels | The value is within the selected interval, including endpoints |
data-disabled="true" | Steps, step dots, marks, mark labels | Inherits the slider's disabled state |
data-orientation | Steps and marks containers | horizontal or vertical |
data-direction | Steps and marks containers | ltr or rtl, derived from the locale |
Interactive States
The component supports both CSS pseudo-classes and data attributes for flexibility:
- Hover:
:hoveror[data-hovered="true"]on thumb - Focus:
:focus-visibleor[data-focus-visible="true"]on thumb - Dragging:
[data-dragging="true"]on thumb - Disabled:
:disabledor[data-disabled="true"]on slider or thumb
API Reference
Slider
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | number[] | - | The current value (controlled) |
defaultValue | number | number[] | - | The default value (uncontrolled) |
onChange | (value: number | number[]) => void | - | Handler called when the value changes |
onChangeEnd | (value: number | number[]) => void | - | Handler called when dragging ends |
minValue | number | 0 | The slider's minimum value |
maxValue | number | 100 | The slider's maximum value |
step | number | 1 | Value increment and spacing between dots when Slider.Steps is present |
formatOptions | Intl.NumberFormatOptions | - | The display format of the value label |
orientation | "horizontal" | "vertical" | "horizontal" | The orientation of the slider |
isDisabled | boolean | - | Whether the slider is disabled |
aria-label | string | - | Accessibility label for the slider |
aria-labelledby | string | - | ID of element that labels the slider |
className | string | - | Additional CSS classes |
children | ReactNode | RenderFunction | - | Slider content or render function |
render | DOMRenderFunction<keyof React.JSX.IntrinsicElements, SliderRenderProps> | - | Overrides the default DOM element with a custom render function. |
Slider.Output
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
children | ReactNode | RenderFunction | - | Output content or render function |
render | DOMRenderFunction<keyof React.JSX.IntrinsicElements, SliderOutputRenderProps> | - | Overrides the default DOM element with a custom render function. |
Slider.Track
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
children | ReactNode | RenderFunction | - | Track content or render function |
render | DOMRenderFunction<keyof React.JSX.IntrinsicElements, SliderTrackRenderProps> | - | Overrides the default DOM element with a custom render function. |
Slider.Fill
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
style | CSSProperties | - | Inline styles |
Slider.Thumb
| Prop | Type | Default | Description |
|---|---|---|---|
index | number | 0 | Index of the thumb within the slider |
isDisabled | boolean | - | Whether this thumb is disabled |
name | string | - | The name of the input element, used when submitting an HTML form |
className | string | - | Additional CSS classes |
children | ReactNode | RenderFunction | - | Thumb content or render function |
render | DOMRenderFunction<keyof React.JSX.IntrinsicElements, SliderThumbRenderProps> | - | Overrides the default DOM element with a custom render function. |
Slider.Steps
Renders decorative dots inside Slider.Track using the root slider's bounds and step. It generates its own children and accepts standard DOM props and a ref.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes for the container |
style | CSSProperties | - | Inline styles for the container |
render | DOMRenderFunction<keyof React.JSX.IntrinsicElements, undefined> | - | Overrides the default DOM element with a custom render function |
Slider.Marks
Contains Slider.Mark children. Place it directly inside Slider, after Slider.Track. Accepts standard DOM props and a ref.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Mark labels |
className | string | - | Additional CSS classes for the container |
style | CSSProperties | - | Inline styles for the container |
render | DOMRenderFunction<keyof React.JSX.IntrinsicElements, undefined> | - | Overrides the default DOM element with a custom render function |
Slider.Mark
A label positioned at a value within Slider.Marks. Accepts standard DOM props and a ref.
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | Required | Value at which to position the label; non-finite or out-of-bounds values are not rendered |
children | ReactNode | Formatted value | Custom label content; otherwise uses the slider's locale and formatOptions |
className | string | - | Additional CSS classes |
style | CSSProperties | - | Additional inline styles; value positioning is managed automatically |
render | DOMRenderFunction<keyof React.JSX.IntrinsicElements, undefined> | - | Overrides the default DOM element with a custom render function |
Render Props
When using render functions with Slider.Output or Slider.Track, these values are provided:
| Prop | Type | Description |
|---|---|---|
state | SliderState | The state of the slider |
values | number[] | Values managed by the slider by thumb index |
getThumbValueLabel | (index: number) => string | Returns the string label for the specified thumb's value |
orientation | "horizontal" | "vertical" | The orientation of the slider |
isDisabled | boolean | Whether the slider is disabled |
Accessibility
The Slider component implements the ARIA slider pattern and provides:
- Full keyboard navigation support (Arrow keys, Home, End, Page Up/Down)
- Screen reader announcements for value changes
- Proper focus management
- Support for disabled states
- HTML form integration via hidden input elements
- Internationalization support with locale-aware value formatting
- Right-to-left (RTL) language support
- Step dots are decorative, hidden from assistive technology, and add no tab stops
- Mark labels remain readable text and do not replace the slider's accessible label or value announcements
For more information, see the React Aria Slider documentation.





