Slider
Range input with a themeable track, thumb, step ticks and value bubble.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
mode | SliderMode | single | single for one value, range for two thumbs selecting valueStart–valueEnd. |
value | number | 0 | Current value, clamped to min/max and snapped to step by the inner input. |
value-start | number | 0 | Lower end of the selected interval in range mode. Kept at or below valueEnd. |
value-end | number | 100 | Upper end of the selected interval in range mode. Kept at or above valueStart. |
min | number | 0 | Minimum selectable value. |
max | number | 100 | Maximum selectable value. |
step | number | 1 | Increment between values; also the distance between ticks. |
disabled | boolean | false | Disables the control: no interaction, rendered dimmed. |
name | string | — | Form field name forwarded to the inner input. |
orientation | SliderOrientation | horizontal | Direction of the track. A vertical slider takes --c2-slider__container--length as its height. |
show-value | boolean | false | Shows the value in a bubble above the thumb while hovering, dragging or focused. |
ticks | boolean | false | Draws a mark on the track for every step between min and max (up to 200 marks). |
start-label | string | Minimum | Accessible name of the lower thumb in range mode, appended to aria-label when that is set ("Price, Minimum"). |
end-label | string | Maximum | Accessible name of the upper thumb in range mode, appended to aria-label when that is set. |
aria-label | string | — | Accessible name used when no visible label names the slider. |
aria-labelledby | undefined | string | — | Id of the element that labels the slider. |
Events
| Name | Type | Description |
|---|---|---|
input | Event | Re-dispatched from the inner input while the value changes (every step of a drag). In range mode, read valueStart/valueEnd. |
change | Event | Re-dispatched from the inner input when the value is committed (pointer released, key released). |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
track | The complete slider track. |
fill | The track segment before the current value (between the two thumbs in range mode). |
thumb | The draggable value handle (both handles in range mode). |
thumb-start | The lower handle in range mode. |
thumb-end | The upper handle in range mode. |
value | The value bubble shown above the thumb when show-value is set. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-slider__container--height | pixel | 32px | Height of the horizontal slider (width when vertical); the touch target. |
--c2-slider__container--length | pixel | 160px | Length of a vertical slider. A horizontal one fills its width. |
--c2-slider__container__disabled--opacity | opacity | 0.38 | |
--c2-slider__track--height | pixel | 4px | |
--c2-slider__track--border-radius | border-radius | 999px | |
--c2-slider__track--color | color | #e4e4e7 | |
--c2-slider__track__error--color | color | #dc2626 | Unfilled track while an enclosing c2-form-field shows an error. |
--c2-slider__fill--color | color | #0265dc | Filled part of the track, from the start to the thumb. |
--c2-slider__thumb--size | pixel | 18px | |
--c2-slider__thumb--border-radius | border-radius | 999px | |
--c2-slider__thumb--color | color | #ffffff | |
--c2-slider__thumb--border | border | 2px solid #0265dc | |
--c2-slider__thumb--box-shadow | box-shadow | 0 1px 3px rgba(0, 0, 0, 0.15) | |
--c2-slider__thumb__hover--box-shadow | box-shadow | 0 0 0 6px rgba(2, 101, 220, 0.12) | Halo while hovering. |
--c2-slider__thumb__active--box-shadow | box-shadow | 0 0 0 8px rgba(2, 101, 220, 0.18) | Halo while dragging. |
--c2-slider__thumb__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-slider__thumb__focus--outline-offset | pixel | 2px | |
--c2-slider__tick--size | pixel | 2px | |
--c2-slider__tick--color | color | #a1a1aa | Ticks on the unfilled part of the track. |
--c2-slider__tick__filled--color | color | #ffffff | Ticks on the filled part. |
--c2-slider__value--background | background | #18181b | Value bubble above the thumb. |
--c2-slider__value--color | color | #fafafa | |
--c2-slider__value--font-size | font-size | 12px | |
--c2-slider__value--font-weight | font-weight | 500 | |
--c2-slider__value--border-radius | border-radius | 6px | |
--c2-slider__value--padding | padding | 4px 8px | |
--c2-slider__value--offset | pixel | 8px | Gap between the thumb and the bubble. |
--c2-slider__value--opacity | opacity | 0 | Resting opacity of the bubble; it is fully visible while hovering, dragging or focused. 1 keeps it always on. |