Gathering detailed insights and metrics for @spectrum-web-components/slider
Gathering detailed insights and metrics for @spectrum-web-components/slider
Gathering detailed insights and metrics for @spectrum-web-components/slider
Gathering detailed insights and metrics for @spectrum-web-components/slider
@spectrum-web-components/color-slider
An `<sp-color-slider>` lets users visually change an individual channel of a color. The background of the `<sp-color-slider>` is a visual representation of the range of values a user can select from. This can represent color properties such as hues, color
@spectrum-web-components/color-handle
The `<sp-color-handle>` is used to select a colour on an `<sp-color-area>`, `<sp-color-slider>`, or `<sp-color-wheel>`. It functions similarly to the handle on an `<sp-slider>`.
@spectrum-web-components/color-area
An `<sp-color-area>` allows users to visually select two properties of a color simultaneously. It's commonly used together with a color slider or color wheel.
@swc-react/slider
React and Next.js wrapper of the @spectrum-web-components/slider component
npm install @spectrum-web-components/slider
Typescript
Module System
Node Version
NPM Version
TypeScript (66.41%)
CSS (31.37%)
JavaScript (2.07%)
HTML (0.08%)
Handlebars (0.06%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
1,405 Stars
4,923 Commits
229 Forks
46 Watchers
249 Branches
342 Contributors
Updated on Jul 17, 2025
Latest Version
1.7.0
Package Id
@spectrum-web-components/slider@1.7.0
Unpacked Size
525.90 kB
Size
73.67 kB
File Count
52
NPM Version
10.8.1
Node Version
20.16.0
Published on
Jun 11, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
<sp-slider>
allows users to quickly select a value within a range. They should be used when the upper and lower bounds of the range are invariable.
yarn add @spectrum-web-components/slider
Import the side effectful registration of <sp-slider>
via:
import '@spectrum-web-components/slider/sp-slider.js';
When leveraging the editable
attribute, the @spectrum-web-components/number-field/sp-number-field.js
dependency will be asynchronously loaded via a dynamic import to reduce JS payload for applications not leveraging this feature. In the case that you would like to import those transverse dependencies statically, import the side effectful registration of <sp-slider>
as follows:
import '@spectrum-web-components/slider/sync/sp-slider.js';
When looking to leverage the Slider
base class as a type and/or for extension purposes, do so via:
import { Slider } from '@spectrum-web-components/slider';
1<sp-slider label="Slider Label"></sp-slider> 2<sp-slider label="Slider Label - Disabled" disabled></sp-slider>
By default, an <sp-slider>
element has both a "text" label and a "value" label. The "value" label is output by the element itself based on its state, but the "text" label must be supplied by the consuming developer in order for the <sp-slider>
to be delivered in an accessible manner.
Either or both of these can be suppressed visually as needed by your application UI, while still fulfilling their role in delivering a quality accessibility tree to the browser. This delivery is controlled by the label-visibility
attribute (or labelVisibility
property) which accepts text
, value
, or none
as values.
Use label-visibility="text"
to suppress the "value" label, use label-visibility="value"
to suppress the "text" label, or use label-visibility="none"
to suppress the "text" label. In each case outlined above the content for both labels will be made available to screen readers, so be sure to manage the content delivered to visitors in that context.
1<sp-slider 2 label="No visible value label" 3 label-visibility="text" 4 value="50" 5></sp-slider>
1<sp-slider label="No visible text label" label-visibility="value"></sp-slider>
1<sp-slider label="No visible labels" label-visibility="none"></sp-slider>
The slider also optionally accepts two or more <sp-slider-handle>
elements with slot="handle"
:
1<sp-slider step="1" min="0" max="255"> 2 Output Levels 3 <sp-slider-handle 4 slot="handle" 5 name="low" 6 label="Low" 7 value="5" 8 max="next" 9 ></sp-slider-handle> 10 <sp-slider-handle 11 slot="handle" 12 name="mid" 13 label="Mid" 14 value="100" 15 min="previous" 16 max="next" 17 ></sp-slider-handle> 18 <sp-slider-handle 19 slot="handle" 20 name="high" 21 label="High" 22 value="250" 23 min="previous" 24 ></sp-slider-handle> 25</sp-slider>
1<sp-slider label="Slider Label" size="s"></sp-slider> 2<sp-slider label="Slider Label - Editable" editable size="s"></sp-slider>
1<sp-slider label="Slider Label"></sp-slider> 2<sp-slider label="Slider Label - Editable" editable></sp-slider>
1<sp-slider label="Slider Label" size="l"></sp-slider> 2<sp-slider label="Slider Label - Editable" editable size="l"></sp-slider>
1<sp-slider label="Slider Label" size="xl"></sp-slider> 2<sp-slider label="Slider Label - Editable" editable size="xl"></sp-slider>
An <sp-slider>
element can be paired with an <sp-number-field>
element via the editable
attribute. The <sp-number-field>
will be passed all of the standard options from the <sp-slider>
element (e.g. min
, max
, formatOptions
, etc.) and will also accept the hide-stepper
attribute in order to prevent the display of its stepper UI.
The quiet
attribute applies Quiet styling to the number field when a slider is editable
.
1<sp-slider 2 label="Hours of the day (editable)" 3 editable 4 max="24" 5 min="0" 6 value="7.25" 7 step="0.25" 8 style="--spectrum-slider-editable-number-field-width: 100px;" 9 format-options='{ 10 "style": "unit", 11 "unit": "hour" 12 }' 13></sp-slider>
1<sp-slider 2 label="Angle (editable)" 3 editable 4 hide-stepper 5 min="0" 6 max="360" 7 format-options='{ 8 "style": "unit", 9 "unit": "degree", 10 "unitDisplay": "narrow" 11 }' 12></sp-slider>
1<sp-slider quiet editable value="50"></sp-slider> 2<sp-slider quiet editable hide-stepper value="50"></sp-slider>
Use variant="filled"
to add a filled style to the slider from a starting point to the current value. By default the starting point is the min
value.
1<sp-slider 2 label="Slider Label" 3 max="1" 4 variant="filled" 5 min="0" 6 value=".5" 7 step="0.01" 8></sp-slider> 9<sp-slider 10 label="Slider Label - Disabled" 11 max="1" 12 variant="filled" 13 min="0" 14 value=".5" 15 step="0.01" 16 disabled 17></sp-slider>
When both fill-start
and variant="filled"
are used in <sp-slider>
, the fill-start
property defines the starting point. If fill start does not have a number associated with it, the starting point will be the value
.
Any number (including 0
) can be used as a fill-start value. If a custom normalization function is provided, it will also normalize all fill-related params.
1<sp-slider 2 label="Slider Label" 3 max="1" 4 fill-start 5 variant="filled" 6 min="0" 7 value=".5" 8 step="0.01" 9></sp-slider> 10<sp-slider 11 label="Slider Label" 12 max="1" 13 fill-start 14 variant="filled" 15 min="0" 16 value=".8" 17 step="0.01" 18 disabled 19></sp-slider>
1<sp-slider 2 id="fill-start-slider" 3 label="fill-start greater than value" 4 max="1" 5 min="0" 6 value=".3" 7 step="0.1" 8 fill-start="0.7" 9 variant="filled" 10></sp-slider>
1<sp-slider 2 id="fill-start-slider" 3 label="Fill Start less than Value" 4 max="1" 5 min="0" 6 value=".7" 7 step="0.1" 8 fill-start="0.25" 9 variant="filled" 10></sp-slider>
1<sp-slider 2 label="fill-start set to 0" 3 max="1" 4 min="-1" 5 value=".7" 6 step="0.1" 7 fill-start="0" 8 variant="filled" 9></sp-slider>
With variant="tick"
, ticks are applied at intervals defined with the tick-step
attribute. The tick-labels
attribute will apply labels to the ticks.
1<sp-slider label="Slider Label" variant="tick" tick-step="5"></sp-slider> 2<sp-slider 3 label="Slider Label - Disabled" 4 variant="tick" 5 tick-step="5" 6 disabled 7></sp-slider>
1<sp-slider 2 label="Slider Label" 3 variant="tick" 4 tick-step="5" 5 tick-labels 6></sp-slider> 7<sp-slider 8 label="Slider Label - Disabled" 9 variant="tick" 10 tick-step="5" 11 tick-labels 12 disabled 13></sp-slider>
With variant="ramp"
, the slider with increases as it approaches the max
position.
1<sp-slider label="Slider Label" variant="ramp"></sp-slider> 2<sp-slider label="Slider Label - Disabled" variant="ramp" disabled></sp-slider>
The "range"
variant along with two handles to create a range slider. (See slider handle.)
1<sp-slider variant="range" step="1" min="0" max="255"> 2 Output Levels 3 <sp-slider-handle 4 slot="handle" 5 name="min" 6 label="Minimum" 7 value="5" 8 ></sp-slider-handle> 9 <sp-slider-handle 10 slot="handle" 11 name="max" 12 label="Maximum" 13 value="250" 14 ></sp-slider-handle> 15</sp-slider>
An <sp-slider>
or <sp-slider-handle>
element will process its numeric value with new Intl.NumberFormat(this.resolvedLanguage, this.formatOptions).format(this.value)
in order to prepare it for visual delivery in the input. In order to customize this processing supply your own Intl.NumberFormatOptions
via the formatOptions
property, or format-options
attribute as seen below.
this.resolvedLanguage
represents the language in which the <sp-slider>
or <sp-slider-handle>
element is currently being delivered. By default, this value will represent the language established by the lang
attribute on the root <html>
element while falling back to navigator.language
when that is not present. This value can be customized via a language context provided by a parent element that listens for the sp-language-context
event and supplies updated language settings to the callback
function contained therein. Applications leveraging the <sp-theme>
element to manage the visual delivery or text direction of their content will also be provided a reactive context for supplying language information to its descendants.
1<sp-slider 2 min="0" 3 max="1" 4 step="0.01" 5 value="0.5" 6 label="Slider Label" 7 format-options='{ 8 "style": "percent" 9 }' 10></sp-slider>
More advanced formatting is available by specifying a formatting function to
the getAriaHandleText
property on an sp-slider
or sp-slider-handle
. Or,
for a multi-handle slider, you can format the combined value label for all
handles by passing a formatting function to the getAriaValueText
property
on the parent sp-slider
.
Intl.NumberFormatOptions
While Intl.NumberFormatOptions
does support a wide range of units, it is possible to encounter units (e.g. the graphics units of pixel
, pixels
, points
, etc.) that are not supported therein. When this occurs, an <sp-slider>
element will attempt to polyfill support for this unit. See the following example delivering { style: "unit", unit: "px" }
below:
1<sp-slider 2 style="width: 200px" 3 value="500" 4 format-options='{ 5 "style": "unit", 6 "unit": "px" 7 }' 8> 9 Document width in pixels 10</sp-slider>
Note: the polyfilling done here is very simplistic and is triggered by supplying options that would otherwise cause the Intl.NumberFormat()
call to throw an error. Once the unsupporting unit of px
causes the construction of the object to throw, a backup formatter/parser pair will be created without the supplied unit data. When the style
is set to unit
, the unit
value will be adopted as the static unit display. This means that neither pluralization nor translation will be handled within the <sp-number-field>
element itself. If pluralization or translation is important to the delivered interface, please be sure to handle passing those strings into to element via the formatOptions
property reactively to the value of the element or locale of that page in question.
Slider will reset to its default-value
when the user double clicks on the slider handle or if the user presses the escape
key when the slider handle is focused.
1<sp-slider value="50" default-value="20"></sp-slider>
Note: If a slider with default-value
attribute is contained in a modal and the slider handle is focused then the following interaction will occur on pressing the escape
key:
By default, sp-slider
assumes a linear scale between the min
and max
values.
For advanced applications, it is sometimes necessary to specify a custom
"normalization."
Normalization is the process of converting a slider to a value between 0 and 1 where 0 represents the minimum and 1 represents the maximum. See the "Three Handles Complex" example in the playground.
1<sp-slider disabled value="50"></sp-slider> 2<sp-slider disabled quiet value="50"></sp-slider> 3<sp-slider disabled editable value="50"></sp-slider> 4<sp-slider disabled variant="filled" value="50"></sp-slider> 5<sp-slider disabled variant="ticks" value="50"></sp-slider> 6<sp-slider disabled variant="ramp" value="50"></sp-slider>
The indeterminate attribute will be passed to the internal <sp-number-field>
element and alter its visual delivery until a change has been made to the <sp-slider>
element at which point the change
event that is dispatched can be understood as always removing the indeterminate attribute from the <sp-slider>
.
1<sp-slider indeterminate value="50"></sp-slider> 2<sp-slider indeterminate quiet value="50"></sp-slider> 3<sp-slider indeterminate editable value="50"></sp-slider> 4<sp-slider indeterminate variant="filled" value="50"></sp-slider> 5<sp-slider indeterminate variant="ticks" value="50"></sp-slider> 6<sp-slider indeterminate variant="ramp" value="50"></sp-slider>
Like the <input type="range">
element after which the <sp-slider>
is fashioned, it will dispatch input
events in a stream culminating with a change
event (representing the final commit of the value
to the element) once the user has finished interacting with the element. Both other these events can access the value
of their dispatching target via event.target.value
. In this way, a steaming listener pattern similar to the following can prove useful:
1const slider = document.querySelector('sp-slider'); 2 3const endListener = ({ target }) => { 4 target.addEventListener('input', startListener); 5 target.removeEventListener('input', streamListener); 6 target.removeEventListener('change', endListener); 7 console.log(target.value); 8}; 9 10const streamListener = ({ target }) => { 11 console.log(target.value); 12}; 13 14const startListener = ({ target }) => { 15 target.removeEventListener('input', startListener); 16 target.addEventListener('input', streamListener); 17 target.addEventListener('change', endListener); 18 console.log(target.value); 19}; 20 21slider.addEventListener('input', startListener);
Every slider should have a label. A slider without a label is ambiguous and not accessible. Write the label in sentence case.
In rare cases where context is sufficient and a label doesn't require visibility, make sure to have the design reviewed and approved by an accessibility expert. Use label-visibility
to set which labels should remain visible, and non-visible labels will still be read by assistive technology.
The Tab and Shift+Tab keys are used to navigate to and set focus on the slider control. The Arrow Up (↑) and Arrow Down (↓) keys are used to increment the slider value, respectively.
Because multiple sliders are often used on the same page, the number field in the editable
slider is designed to not be keyboard focusable via Tab or Shift+Tab keys. (See WAI ARIA APG's Keyboard Navigation Inside Components.) Since the slider itself can already be incremented via the arrow keys, a roving tabindex controller cannot be used within the slider; therefore, the number field will not be keyboard navigable.
Review the accessibility guidelines for the slider handle.
No vulnerabilities found.
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
Found 24/28 approved changesets -- score normalized to 8
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
36 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More