Slider

free

Slider selects a number or a range by dragging a thumb along a track.

import Slider from '@/components/ui/slider';

export default function UsageDemo() {
  return (

Installation

Add this component with the NateUI CLI.

npx nateui@latest add Slider

Examples

Range

import Slider from '@/components/ui/slider';

export default function RangeDemo() {
  return (

Disabled

import Slider from '@/components/ui/slider';

export default function DisabledDemo() {
  return (

Tooltips

Show on hover
Always visible
60
Custom content
import Slider from '@/components/ui/slider';

export default function TooltipsDemo() {
  return (

Marks

$20k
$50k
$80k
import Slider from '@/components/ui/slider';

const marks = [
  { value: 20, label: '$20k' },

Capsule

20
50
80
import Slider from '@/components/ui/slider';

const capsuleMarks = [
  { value: 20, label: '20' },

Step

0°C
25°C
50°C
75°C
100°C
0°C
26°C
37°C
100°C
import Slider from '@/components/ui/slider';

const evenMarks = [
  { value: 0, label: '0°C' },

Min And Max

import Slider from '@/components/ui/slider';

export default function MinAndMaxDemo() {
  return (

Custom Color

import Slider from '@/components/ui/slider';

export default function CustomColorDemo() {
  return (

Controlled

Value: 50
Range: 20 – 50
import { useState } from 'react';
import Slider from '@/components/ui/slider';

export default function ControlledDemo() {

API

Slider selects a single value; Slider.Range selects a [start, end] pair with two thumbs. Both are uncontrolled with defaultValue or controlled with value and onChange, and both accept native div props.

Slider

PropDescriptionTypeDefault
valueCurrent value in controlled mode.number-
defaultValueInitial value when uncontrolled.number0
onChangeFires with the new value while the value changes.(value: number) => void-
onDraggingStopFires with the final value when a drag or key change ends.(value: number) => void-
minLowest selectable value.number0
maxHighest selectable value.number100
stepIncrement applied while dragging or using arrow keys.number1
marksReference points rendered under the track.SliderMark[][]
stepOnMarksSnap the thumb to mark values instead of stepping by step.boolean-
variantVisual treatment for the slider. capsule uses the thicker rail and embedded marks.SliderVariant'default'
precisionDecimal places kept in the reported value.numberderived from step
tooltipTooltip content, or a function of the current value.SliderTooltipidentity
showTooltipOnHoverShow the tooltip on hover, drag, and focus.booleanfalse
alwaysShowTooltipKeep the tooltip visible at all times.booleanfalse
disabledPrevent interaction and dim the track.booleanfalse
thumbAriaLabelAccessible label for the thumb.string-
nameName of the hidden input holding the value.string-
inputPropsProps spread onto the hidden input.ComponentPropsWithoutRef<'input'>-
classNamesClass names for individual slider parts.SliderClassNames{}
classNameClass names for the root element.string-
refRef forwarded to the root element.Ref<HTMLDivElement>-
...nativePropsNative props for the root div.ComponentProps<'div'>-

Slider.Range

PropDescriptionTypeDefault
valueCurrent range in controlled mode.RangeSliderValue-
defaultValueInitial range when uncontrolled.RangeSliderValue-
onChangeFires with the new range while it changes.(value: RangeSliderValue) => void-
onDraggingStopFires with the final range when a drag or key change ends.(value: RangeSliderValue) => void-
minLowest selectable value.number0
maxHighest selectable value.number100
minRangeSmallest allowed distance between the two thumbs.number0
maxRangeLargest allowed distance between the two thumbs.number-
stepIncrement applied while dragging or using arrow keys.number1
marksReference points rendered under the track.RangeSliderMark[][]
stepOnMarksSnap thumbs to mark values instead of stepping by step.boolean-
variantVisual treatment for the range slider. capsule uses the thicker rail and embedded marks.SliderVariant'default'
precisionDecimal places kept in the reported values.numberderived from step
tooltipTooltip content, or a function of a single thumb value.SliderTooltipidentity
showTooltipOnHoverShow tooltips on hover, drag, and focus.booleanfalse
alwaysShowTooltipKeep both tooltips visible at all times.booleanfalse
disabledPrevent interaction and dim the track.booleanfalse
thumbArialLabelStartAccessible label for the start thumb.string-
thumbAriaLabelEndAccessible label for the end thumb.string-
nameBase name for the hidden -from and -to inputs.string-
inputPropsProps spread onto both hidden inputs.ComponentPropsWithoutRef<'input'>-
classNamesClass names for individual slider parts.RangeSliderClassNames{}
classNameClass names for the root element.string-
refRef forwarded to the root element.Ref<HTMLDivElement>-

Types

type SliderVariant = 'default' | 'capsule'
 
type RangeSliderValue = [number, number]
 
type SliderTooltip = ReactNode | ((value: number) => ReactNode)
 
type SliderMark = { value: number; label?: ReactNode }
 
type RangeSliderMark = { value: number; tooltip?: ReactNode }
 
type SliderClassNames = {
  thumb?: string
  bar?: string
  mark?: string | ((isFilled: boolean) => string)
  track?: string
}
 
type RangeSliderClassNames = {
  thumb?: [string, string]
  bar?: string
  mark?: string
  track?: string
}