Component Blueprints

Slider

An input range slider lets the user specify a numeric value which must be between two specified values.

About Slider#

The slider component is built using a native input form element with the attribute type of "range".

Implementation#

  • slds-slider should be applied to the div containing both the <input> and the <span> that holds the value of the <input>
  • slds-slider__range should be applied to the <input> element
    • The <input> should have a unique ID that matches the for attribute on the form element <label>
  • The slds-slider__range element can accept 4 attributes that describe the input range:
    • value: Current value of the input range
    • min: Minimum value of a specified range
    • max: Maximum value of a specified range
    • step: Indicates the granularity that is expected by limiting the allowed values
  • The slds-slider__value span should be updated with the current value of the <input>
  • The slds-slider__value element must have aria-hidden=true to hide from screen readers as they understand that value already from the <input>
  • The class slds-assistive-text can be placed on the <label>, or either <span> within the <label>, to visually hide the either value (or both).

Mobile#

On mobile devices, such as phones and other devices that have touch as the primary method of interaction, sliders will have an increased size to accommodate using a finger instead of the more precise mouse cursor.

Below is a live example of what to expect in that context. No code changes are needed in the Salesforce platform context as this change occurs automatically in Salesforce native mobile applications. For those users not on the Salesforce platform, these modifications will occur automatically when the secondary touch stylesheet is loaded and the device has touch as the primary method of interaction.

Base#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

States#

Disabled#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Value: 0#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Value: 25#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Value: 50#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Value: 75#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Value: 100#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Examples#

Min/Max Range#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Min/Max Range with Steps#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Width: x-small#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Width: small#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Width: medium#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Width: large#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Error#

There is a problem with this field
<div class="slds-form-element slds-has-error">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Modifiers#

Vertical#

<div class="slds-form-element">
  <label class="slds-form-element__label" for="slider-id-01">
    <span class="slds-slider-label">
      <span class="slds-slider-label__label">Slider Label</span>

Styling Hooks Overview#

Use these CSS Custom Properties as hooks to customize this SLDS component with your own style. For more information, read the technical documentation.

CategoryStyling Hook NameValue Type(s)Fallback Value
Box Shadow
--slds-c-slider-thumb-shadow
String10, rgba(0, 0, 0, 0.16) 0 2px 3px
--slds-c-slider-thumb-shadow-focus
String0 0 3px #0176d3
Color
--slds-c-slider-thumb-color-foreground
Color#0176d3
--slds-c-slider-thumb-color-foreground-active
Color#014486
--slds-c-slider-thumb-color-foreground-focus
Color#014486
--slds-c-slider-thumb-color-foreground-hover
Color#014486
--slds-c-slider-track-color-background
Color95, #f3f3f3
Radius
--slds-c-slider-thumb-radius-border
Dimension50%
--slds-c-slider-track-radius-border
Dimension0.125rem

Overview of CSS Classes#

Selector.slds-slider
Summary

Initializes slider component

Supportdev-ready
Restrictdiv
VariantTrue
Selector.slds-slider__range
Summary

Range track for slider

Restrict.slds-slider input
Selector.slds-slider__value
Summary

Element that contains value of input range

Restrict.slds-slider span
Selector.slds-slider_vertical
Summary

Modifier that makes the slider vertical

Restrict.slds-slider
ModifierTrue

Slider Release Notes

2.17.0

Added

  • Added slds as the default namespace with sds fallbacks for Styling Hooks.
  • Added CSS Custom Property reassignments for variants and states (e.g., focus, active, hover).

2.14.0

Added

  • Enabled styling hooks for slider. See slider's styling hooks overview table for a full listing of the currently available hooks.

2.11.7

Added

  • Added documentation and examples for mobile/touch context

2.11.0

Changed

  • For mobile devices:
    • Increased the tap target size of the slider thumb to $height-tappble (2rem) for increased usability.
    • Minor layout and spacing adjustments to account for the larger slider thumb

2.7.0

Fixed

  • Fixed a bug that prevented Slider background from appearing in IE11.