Color Slider
Features
- Supports all color channels (hue, saturation, lightness, brightness, red, green, blue, alpha).
- Automatic gradient background based on current color.
- Horizontal and vertical orientations.
- Full keyboard navigation support.
- Configurable step values.
- Preserves color precision during drag operations.
- Form integration with hidden inputs.
- Support for HSL, HSB, and RGB color spaces.
Installation
Install the component from your command line.
$ npm add reka-uiLooking for a complete color picker? Check out the Color Picker example that combines Color Area, Color Slider, Color Field, and Color Swatch components.
Anatomy
Import all parts and piece them together.
<script setup>
import {
ColorSliderRoot,
ColorSliderThumb,
ColorSliderTrack,
} from 'reka-ui'
</script>
<template>
<ColorSliderRoot channel="hue">
<ColorSliderTrack />
<ColorSliderThumb />
</ColorSliderRoot>
</template>API Reference
ColorSliderRoot
The root component that provides the slider functionality and context.
| Prop | Default | Type |
|---|---|---|
as | 'span' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
channel* | 'hue' | 'saturation' | 'red' | 'green' | 'blue' | 'alpha' | 'lightness' | 'brightness'The color channel that this slider manipulates. | |
colorSpace | 'hsl' | 'hsl' | 'rgb' | 'hsb'The color space to operate in. |
defaultValue | '#000000' | string | ColorThe default color value (uncontrolled). |
dir | 'ltr' | 'rtl'The reading direction of the slider. | |
disabled | false | booleanWhen |
inverted | false | booleanWhether the slider is visually inverted. |
modelValue | string | ColorThe color value (controlled). Can be a hex string or Color object. | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
orientation | 'horizontal' | 'vertical' | 'horizontal'The orientation of the slider. |
required | booleanWhen | |
step | numberCustom step value for increment/decrement. Defaults to the channel's natural step. |
| Emit | Payload |
|---|---|
change | [value: string] |
changeEnd | [value: string] |
update:color | [value: Color] |
update:modelValue | [value: string | Color]Event handler called when the value of the checkbox changes. |
ColorSliderTrack
The track component that displays the color gradient background.
| Prop | Default | Type |
|---|---|---|
as | 'span' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
ColorSliderThumb
The draggable thumb component for selecting values.
| Prop | Default | Type |
|---|---|---|
as | 'span' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
| Slots (default) | Payload |
|---|---|
channelName | stringThe display name of the current channel |
channelValue | numberThe current numeric value of the channel |
Examples
Hue Slider
A horizontal hue slider in HSL color space.
<script setup>
import {
ColorSliderRoot,
ColorSliderThumb,
ColorSliderTrack,
} from 'reka-ui'
import { ref } from 'vue'
const color = ref('#3b82f6')
</script>
<template>
<ColorSliderRoot
v-model="color"
channel="hue"
color-space="hsl"
>
<ColorSliderTrack />
<ColorSliderThumb />
</ColorSliderRoot>
</template>Alpha Channel
Slider for adjusting the alpha (opacity) channel.
<script setup>
import {
ColorSliderRoot,
ColorSliderThumb,
ColorSliderTrack,
} from 'reka-ui'
import { ref } from 'vue'
const color = ref('#3b82f6')
</script>
<template>
<ColorSliderRoot
v-model="color"
channel="alpha"
>
<ColorSliderTrack />
<ColorSliderThumb />
</ColorSliderRoot>
</template>Vertical Orientation
A vertical slider for space-constrained layouts.
<script setup>
import {
ColorSliderRoot,
ColorSliderThumb,
ColorSliderTrack,
} from 'reka-ui'
import { ref } from 'vue'
const color = ref('#3b82f6')
</script>
<template>
<ColorSliderRoot
v-model="color"
channel="lightness"
orientation="vertical"
class="h-[200px]"
>
<ColorSliderTrack />
<ColorSliderThumb />
</ColorSliderRoot>
</template>RGB Channel Sliders
Sliders for individual RGB channels.
<script setup>
import {
ColorSliderRoot,
ColorSliderThumb,
ColorSliderTrack,
} from 'reka-ui'
import { ref } from 'vue'
const color = ref('#3b82f6')
</script>
<template>
<div class="flex flex-col gap-4">
<ColorSliderRoot
v-model="color"
channel="red"
color-space="rgb"
>
<ColorSliderTrack />
<ColorSliderThumb />
</ColorSliderRoot>
<ColorSliderRoot
v-model="color"
channel="green"
color-space="rgb"
>
<ColorSliderTrack />
<ColorSliderThumb />
</ColorSliderRoot>
<ColorSliderRoot
v-model="color"
channel="blue"
color-space="rgb"
>
<ColorSliderTrack />
<ColorSliderThumb />
</ColorSliderRoot>
</div>
</template>Custom Step Value
Use a custom step increment for finer or coarser control.
<script setup>
import {
ColorSliderRoot,
ColorSliderThumb,
ColorSliderTrack,
} from 'reka-ui'
import { ref } from 'vue'
const color = ref('#3b82f6')
</script>
<template>
<ColorSliderRoot
v-model="color"
channel="hue"
:step="5"
>
<ColorSliderTrack />
<ColorSliderThumb />
</ColorSliderRoot>
</template>Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
ArrowLeft | Decreases the value in horizontal orientation. |
ArrowRight | Increases the value in horizontal orientation. |
ArrowUp | Increases the value in vertical orientation. |
ArrowDown | Decreases the value in vertical orientation. |
PageUp | Increases the value by a larger step. |
PageDown | Decreases the value by a larger step. |
Home | Sets the value to minimum. |
End | Sets the value to maximum. |
