Skip to main content Sidebar
On this page

Slider

<pc-slider> Since  1.0.0-alpha.4 Experimental

Sliders allow the user to select a single value within a given range.

<pc-slider
    label="Number of users"
    hint="Limit six per team"
    name="value"
    value="3"
    min="0"
    max="6"
    with-markers
    has-tooltip
>
    <span slot="reference">Less</span>
    <span slot="reference">More</span>
</pc-slider>
Code Edit

This component works well with standard <form> elements. Please refer to the form controls page to learn more about form submission and client‐side validation.

Demos

Labels

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

Edit

Hint

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

Edit

Showing tooltips

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

Edit

Setting min, max and step

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

Edit

Showing markers

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.

Edit

Adding references

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

Edit

If you want to show a reference next to a specific marker, you can add position: absolute to it and set the inset-block-start, inset-block-end, inset-inline-start or inset-inline-end property to a percentage that corresponds to the marker’s position.

Value formatting

Customise 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. You can use the Intl.NumberFormat API to format numbers in many ways.

Edit

Range selection

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.

Edit

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("pc-slider[range]");

console.log(`Minimum value: ${slider.minValue}, maximum value: ${slider.maxValue}`);

slider.minValue = 30;
slider.maxValue = 70;

Vertical

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

Edit

Range sliders can also be vertical.

Edit

Size

Control the slider’s size using the size attribute.

Edit

Indicator offset

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.

Edit

Disabled

Use the disabled attribute to disable a slider.

Edit

Properties

NameDescriptionReflectsDefault
validationTargetOverrides the validation target to point to the focusable element.
labelThe slider’s label. If you need to provide HTML in the label, use the label slot instead.
Type: string
""
hintThe slider’s hint. If you need to display HTML, use the hint slot instead.
Type: string
""
nameThe name of the slider, submitted as a name/value pair with form data.
Type: string
minValue
min-value
The minimum value of a range selection. This is only used when the range attribute is set.
Type: number
0
maxValue
max-value
The maximum value of a range selection. This is only used when the range attribute is set.
Type: number
50
defaultValue
value
The default value of the slider. Primarily used for resetting the slider.
Type: number
valueThe current value of the slider, submitted as a name/value pair with form data.
Type: number
rangeConverts the slider to a range slider with two thumbs.
Type: boolean
false
isRangeGet if this is a range slider.
Type: boolean
disabledDisables the slider.
Type: boolean
false
readonlyMakes the slider a read‐only field.
Type: boolean
false
orientationThe orientation of the slider.
Type: "horizontal" | "vertical"
"horizontal"
sizeThe slider’s size.
Type: "small" | "medium" | "large"
"medium"
indicatorOffset
indicator-offset
The starting value from which to draw the slider’s fill, which is based on its current value.
Type: number | undefined
minThe minimum value allowed.
Type: number
0
maxThe maximum value allowed.
Type: number
100
stepThe granularity the value must adhere to when incrementing and decrementing the value.
Type: number
1
requiredIndicates if the slider must be interacted with or not.
Type: boolean
false
autofocusTells the browser to focus the slider when the page loads or a dialog is shown.
Type: boolean
tooltipDistance
tooltip-distance
The distance of the tooltip from the slider’s thumb.
Type: number
8
tooltipPlacement
tooltip-placement
The placement of the tooltip in reference to the slider’s thumb.
Type: "top" | "right" | "bottom" | "left"
"top"
withMarkers
with-markers
Adds markers at each step along the slider.
Type: boolean
false
hasTooltip
has-tooltip
Adds a tooltip above the thumb when the control has focus or is dragged.
Type: boolean
false
valueFormatterA custom formatting function to apply to the value. This will be shown in the tooltip and announced by screen readers and is property only.
Type: (value: number) => string | undefined
updateComplete A read‐only promise that resolves when the component has finished updating.

Learn more about customising animations.

Slots

NameDescription
labelThe slider label. Alternatively, you can use the label attribute.
hintText that describes how to use the input. Alternatively, you can use the hint attribute.
referenceOne or more reference labels to show visually below the slider.

Learn more about using slots.

Methods

NameDescriptionArguments
focus()Focuses the slider.
blur()Unfocuses the slider (i.e., blurs it).
stepDown()Decreases the slider’s value by step. This is a programmatic change, so change and input events will not be emitted when this is called.
stepUp()Increases the slider’s value by step. This is a programmatic change, so change and input events will not be emitted when this is called.

Learn more about methods.

Events

NameDescriptionEvent detail
changeEmitted when an alteration to the control’s value is committed by the user.Event
focusEmitted when the control gains focus.FocusEvent
blurEmitted when the control loses focus.FocusEvent
inputEmitted when the control receives input.InputEvent
pc-invalidEmitted when the slider has been checked for validity and its constraints aren’t satisfied.

Learn more about events.

Custom properties

NameDescriptionDefault
--track-sizeThe height or width of the slider's track.0.75em
--marker-widthThe width of each individual marker.0.1875em
--marker-heightThe height of each individual marker.0.1875em
--thumb-widthThe width of the thumb.1.25em
--thumb-heightThe height of the thumb.1.25em

Learn more about customising custom properties.

Parts

NameDescription
labelThe element that contains the slider’s label.
hintThe element that contains the slider’s hint.
sliderThe focusable element with role="slider". Contains the track and reference slot.
trackThe slider’s track.
indicatorThe colored indicator that shows from the start of the slider to the current value.
markersThe container that holds all the markers when with-markers is used.
markerThe individual markers that are shown when with-markers is used.
referencesThe container that holds references that get slotted in.
thumbThe slider’s thumb.
thumb-minThe thumb representing the minimum value in a range slider.
thumb-maxThe thumb representing the maximum value in a range slider.
tooltipThe tooltip, a <pc-tooltip> element.
tooltip-tooltipThe tooltip’s tooltip part.
tooltip-contentThe tooltip’s content part.
tooltip-arrowThe tooltip’s arrow part.

Learn more about customising CSS parts.

Importing

If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.

CDN (script tag)CDN (import)npm (import)

To manually import this component from the CDN, copy this code snippet and paste it in your HTML.

<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.4/cdn/components/slider/slider.js"></script>

To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.

import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.4/cdn/components/slider/slider.js";

To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

import "placer-toolkit/dist/components/slider/slider.js";

Dependencies

This component automatically imports these components:

We’d love to hear from you. Please reach out to us with any questions or enquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Dangerous lands

Whoa! You’ve wandered into the dangerous lands of Placer Toolkit. Version 0 is out of date and doesn’t meet EU privacy standards, including GDPR.

Want the latest powers, security and compliance? Stick with the current version of Placer Toolkit!

Yikes! Power up!

Our site is 100 % cookie‐free! We value your privacy, which is why we don’t store any cookies or personal information related to you.

Your browser history is safe from crumbs, and your data is protected, aligning with modern privacy standards like the GDPR. Enjoy your visit without a single digital cookie in sight! 🍪🚫

View our Privacy Policy for more information.

Got it!