An input range slider for specifying a value between two specified numbers.
For Use In
Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline
A lightning-slider component is a horizontal or vertical slider for
specifying a value between two specified numbers. For example, this slider can
be used to capture user input about order quantity or when you want to use an
input field of type="range". To orient the slider vertically, set
type="vertical". Older browsers that don’t support the slider fallback and
treat it as type="text".
Here’s an example of a slider with a step increment of 10.
1<template>2 <lightning-slider3 label="Volume"4 step="10"5 value={myValue}6 onchange={handleChange}7 >8 </lightning-slider>9 <div class="slds-m-vertical_medium">10 <p>11 The value of the slider is:12 <span class="slds-text-heading_small">{myValue}</span>13 </p>14 </div>15</template>
Handle the change event and get the slider value by using the event.detail property.
lightning-slider implements the slider blueprint in the Salesforce Lightning Design System (SLDS). The slider adapts to SLDS 1 or SLDS 2 styling based on the org’s theme or the container app that you use.
Client-side input validation is available for this component. Note that a disabled slider is always valid.
To programmatically show error messages on invalid fields, use the reportValidity() method.
For custom validity error messages, specify the message using setCustomValidity() and reportValidity().
For more information, see the lightning-input documentation.
Component Styling
Use a combination of variants, sizes, positioning type, and utility classes to customize the slider.
Variants
Specify the variant attribute with one of these values.
standard is the default variant, which includes the text label before the range values and slider
label-hidden hides the text label from view
Sizes
Specify the size attribute with one of these values.
x-small takes up a width of 192px
small takes up a width of 240px
medium takes up a width of 320px
largetakes up a width of 400px
The default slider size takes up the width of the view port.
Positioning Type
Specify the type attribute with one of these attributes.
horizontal is the default position type, which places the slider horizontally across the view port
vertical places the slider vertically with a height of 192px
Utility Classes
To apply additional styling, use the SLDS utility classes with the class attribute.
This example adds padding above the slider using an SLDS class.
Component styling hooks provide CSS custom properties that use the --slds-c-* prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the SLDS 1 component blueprints for available component styling hooks.
Use the change event to detect changes to the slider value instead of the blur
event. Browsers such as Safari don’t give focus to the slider so the blur event doesn’t fire.
By default, the min and max values are 0 and 100, but you can specify your
own values. If you specify your own step increment value, you can drag the
slider based on the step increment only. If you set the value lower than the
min value, then the value is set to the min value. Similarly, setting the
value higher than the max value results in the value being set to the max
value.
For precise numerical values, we recommend using the lightning-input
component of type="number" instead.
Attributes
Name
Description
Type
Default
Required
disabled
If present, the slider is disabled and users cannot interact with it.
boolean
false
label
Text label to describe the slider. Provide your own label to describe the slider.
string
max
The maximum value of the input range. The default is 100.
number
100
message-when-bad-input
Error message to be displayed when a bad input is detected.
string
message-when-pattern-mismatch
Error message to be displayed when a pattern mismatch is detected.
string
message-when-range-overflow
Error message to be displayed when a range overflow is detected.
string
message-when-range-underflow
Error message to be displayed when a range underflow is detected.
string
message-when-step-mismatch
Error message to be displayed when a step mismatch is detected.
string
message-when-too-long
Error message to be displayed when the value is too long.
string
message-when-type-mismatch
Error message to be displayed when a type mismatch is detected.
string
message-when-value-missing
Error message to be displayed when the value is missing.
string
min
The minimum value of the input range. The default is 0.
number
0
size
The size of the slider. The default is an empty string, which sets the slider to the width of the viewport. Accepted values are x-small, small, medium, and large.
string
step
The step increment value of the input range. Example steps include 0.1, 1, or 10. The default is 1.
number
1
type
The type determines the orientation of the slider. Accepted values are vertical and horizontal. The default is horizontal.
string
horizontal
validity
Represents the validity states of the slider input, with respect to constraint validation.
object
value
The numerical value of the slider. The default is 0.
number
0
variant
The variant changes the appearance of the slider. Accepted variants include standard and label-hidden. The default is standard.
string
standard
Methods
Name
Description
Argument Name
Argument Type
Argument Description
blur
Removes keyboard focus from the input element.
checkValidity
Returns the valid attribute value (Boolean) on the ValidityState object.
focus
Sets focus on the input element.
reportValidity
Displays the error messages and returns false if the input is invalid. If the input is valid, reportValidity() clears displayed error messages and returns true.
setCustomValidity
Sets a custom error message to be displayed when the slider value is submitted.
message
string
The string that describes the error. If message is an empty string, the error message is reset.
showHelpMessageIfInvalid
Displays error messages on invalid fields. An invalid field fails at least one constraint validation and returns false when checkValidity() is called.