Slider

<wa-slider> Stable Since 2.0

Sliders let users choose a numeric value within a defined range by dragging a thumb along a track.

Less More

This component works with standard <form> elements. Please refer to the section on form controls to learn more about form submission and client-side validation.

Examples

Link to This Section

Labels

Link to This Section

Use the label attribute to give the slider an accessible label. For labels that contain HTML, use the label slot instead.

Hint

Link to This Section

Add descriptive hint to a slider with the hint attribute. For hints that contain HTML, use the hint slot instead.

Showing tooltips

Link to This Section

Use the with-tooltip attribute to display a tooltip with the current value when the slider is focused or being dragged.

Setting min, max, and step

Link to This Section

Use the min and max attributes to define the slider's range, and the step attribute to control the increment between values.

Showing markers

Link to This Section

Use the with-markers attribute to display visual indicators at each step increment. This works best with sliders that have a smaller range of values.

Adding references

Link to This Section

Use the reference slot to add contextual labels below the slider. References are automatically spaced using space-between, making them easy to align with the start, center, and end positions.

Slow Medium Fast

If you want to show a reference next to a specific marker, you can add position: absolute to it and set the left, right, top, or bottom property to a percentage that corresponds to the marker's position.

Formatting the value

Link to This Section

Customize how values are displayed in tooltips and announced to screen readers using the valueFormatter property. Set it to a function that accepts a number and returns a formatted string. The Intl.NumberFormat API is particularly useful for this.



Range selection

Link to This Section

Use the range attribute to enable dual-thumb selection for choosing a range of values. Set the initial thumb positions with the min-value and max-value attributes.

$0 $50 $100

For range sliders, the minValue and maxValue properties represent the current positions of the thumbs. When the form is submitted, both values will be included as separate entries with the same name.

const slider = document.querySelector('wa-slider[range]');

// Get the current values
console.log(`Min value: ${slider.minValue}, Max value: ${slider.maxValue}`);

// Set the values programmatically
slider.minValue = 30;
slider.maxValue = 70;

Vertical Sliders

Link to This Section

Set the orientation attribute to vertical to create a vertical slider. Vertical sliders automatically center themselves and fill the available vertical space.

Range sliders can also be vertical.

Size

Link to This Section

Control the slider's size using the size attribute. Valid options include xs, s, m, l, and xl.





Indicator Offset

Link to This Section

By default, the filled indicator extends from the minimum value to the current position. Use the indicator-offset attribute to change the starting point of this visual indicator.

Easy Moderate Difficult

Disabled

Link to This Section

Use the disabled attribute to disable a slider.

Importing

Link to This Section

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.

CDN npm Self-Hosted React

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/[email protected]/components/slider/slider.js';

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/slider/slider.js';

If you're self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/slider/slider.js';

To import this component for React 18 or below, use the following code:

import WaSlider from '@awesome.me/webawesome/dist/react/slider/index.js';

Slots

Link to This Section

Learn more about using slots.

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Methods

Link to This Section

Learn more about methods.

Events

Link to This Section

Learn more about events.

CSS custom properties

Link to This Section

Learn more about CSS custom properties.

Custom States

Link to This Section

Learn more about custom states.

CSS parts

Link to This Section

Learn more about CSS parts.

Dependencies

Link to This Section

This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.

Need a hand? Report a bug Ask for help
    No results