SwiftUI.js
Components

Slider

Slider is a control for selecting a value from a bounded linear range of values. Slider is built on a native `<input type="range">`, so it keeps standard keyboard support, focus behavior, and form participation.

Slider is a control for selecting a value from a bounded linear range of values. Slider is built on a native `<input type="range">`, so it keeps standard keyboard support, focus behavior, and form participation.

Examples

Basic Usage

Preview unavailable for this example in the static docs build.

Show code
const ControlledSliderDemo = () => {
  const [value, setValue] = useState(50)
  return (
    <VStack spacing={16}>
      <Text>Controlled value: {value}</Text>
      <Slider
        aria-label="Controlled slider"
        value={value}
        onValueChange={setValue}
        min={0}
        max={100}
      />
    </VStack>
  )
}

Uncontrolled Usage

Preview unavailable for this example in the static docs build.

Show code
const UncontrolledSliderDemo = () => {
  return (
    <VStack spacing={16}>
      <Text>Uses browser-managed default value</Text>
      <Slider
        aria-label="Uncontrolled slider"
        defaultValue={35}
        min={0}
        max={100}
        step={5}
      />
    </VStack>
  )
}

Disabled State

Preview unavailable for this example in the static docs build.

Show code
const DisabledSliderDemo = () => {
  return (
    <VStack spacing={16}>
      <Text>Disabled slider</Text>
      <Slider
        aria-label="Disabled slider"
        defaultValue={65}
        min={0}
        max={100}
        disabled
      />
    </VStack>
  )
}

API

PropTypeRequiredDescription
valuenumberNoThe current value of the slider.
defaultValuenumberNoThe initial value of the slider when uncontrolled.
onValueChange(value: number) => voidNoCallback fired when the value changes.
onChange(event: ChangeEvent<HTMLInputElement>) => voidNoNative change event handler forwarded to the underlying input.
minnumberNoThe minimum value of the slider. Default: 0
maxnumberNoThe maximum value of the slider. Default: 100
stepnumberNoThe step increment for the slider. Default: 1
disabledbooleanNoWhether the slider is disabled. Default: false

Inherits additional props from Omit< IBaseElementComponent<'input'>, 'type' | 'value' | 'defaultValue' | 'onChange' | 'children' >.

Overview

Slider is a control for selecting a value from a bounded linear range of values. Slider is built on a native <input type="range">, so it keeps standard keyboard support, focus behavior, and form participation.

SwiftUI Correspondence: Similar to SwiftUI's Slider.

Uncontrolled Usage

Use defaultValue when the browser should own the current value after mount.

Notes

  • Slider supports controlled mode with value and onValueChange
  • Slider supports uncontrolled mode with defaultValue
  • Slider also forwards the native onChange event for web-native integrations
  • Slider supports min, max, step, and disabled
  • Slider participates in native form submission because it renders a real range input
  • Use Slider for continuous value selection

Best Practices

  1. Range: Set appropriate min and max values
  2. Step: Use step for discrete value selection
  3. Feedback: Show the current value to the user when it matters
  4. Accessibility: Provide a label through aria-label, aria-labelledby, or a visible label
  5. Mobile: Test slider interaction on touch devices

On this page