Skip to content

Double Slider

The Double Slider component provides a range slider with two markers that allow users to select a range of values between a minimum and maximum. It’s ideal for filtering data based on ranges like prices, dates, or any numeric values.

The Double Slider component depends on:

  • Slider component (for styling and base functionality)
<!-- Basic double slider -->
<input data-role="double-slider">
<!-- Double slider with min and max values -->
<input data-role="double-slider" data-min="0" data-max="100">
<!-- Double slider with initial values -->
<input data-role="double-slider" data-value-min="25" data-value-max="75">
<!-- Double slider with hints -->
<input data-role="double-slider" data-hint="true">
<!-- Double slider with permanent hints -->
<input data-role="double-slider" data-hint="true" data-hint-always="true">
<!-- Double slider with custom hint masks -->
<input data-role="double-slider"
data-hint="true"
data-hint-mask-min="Min: $1"
data-hint-mask-max="Max: $1">
<!-- Double slider with min/max values displayed -->
<input data-role="double-slider" data-show-min-max="true">
<!-- Double slider with min/max values at the top -->
<input data-role="double-slider"
data-show-min-max="true"
data-min-max-position="top">
<!-- Double slider with target element to display values -->
<input data-role="double-slider" data-target="#rangeValue">
<div id="rangeValue"></div>

For more examples, see the double-slider.html example file in the project.

The Double Slider component supports the following configuration options:

ParameterTypeDefaultDescription
minnumber0Minimum value of the slider
maxnumber100Maximum value of the slider
accuracynumber0Decimal precision for values (0 = integers only)
roundValuebooleantrueWhether to round values according to accuracy
valueMinnumbernullInitial minimum value (defaults to min if not specified)
valueMaxnumbernullInitial maximum value (defaults to max if not specified)
hintbooleanfalseShow hints when dragging markers
hintAlwaysbooleanfalseAlways show hints, not just when dragging
hintPositionMinstring”top”Position of the minimum value hint (“top” or “bottom”)
hintPositionMaxstring”top”Position of the maximum value hint (“top” or “bottom”)
hintMaskMinstring”$1”Format for minimum value hint ($1 is replaced with the value)
hintMaskMaxstring”$1”Format for maximum value hint ($1 is replaced with the value)
showMinMaxbooleanfalseShow min and max values below/above the slider
minMaxPositionstring”bottom”Position of min/max labels (“top” or “bottom”)
targetstringnullTarget element to display selected values (selector or DOM element)
sizenumber0Width of the slider in pixels (0 = auto/100%)
clsSliderstring""Custom class for the slider container
clsBacksidestring""Custom class for the background track
clsCompletestring""Custom class for the filled portion
clsMarkerstring""Custom class for both markers
clsMarkerMinstring""Custom class for the minimum marker
clsMarkerMaxstring""Custom class for the maximum marker
clsHintstring""Custom class for both hints
clsHintMinstring""Custom class for the minimum hint
clsHintMaxstring""Custom class for the maximum hint
clsMinMaxstring""Custom class for the min/max labels container
clsMinstring""Custom class for the minimum label
clsMaxstring""Custom class for the maximum label

The Double Slider component provides the following events:

EventDescription
onStartTriggered when the user starts dragging a marker
onStopTriggered when the user stops dragging a marker
onMoveTriggered continuously while dragging a marker
onChangeTriggered when the slider value changes
onChangeValueTriggered when the slider value changes (alias for onChange)
onFocusTriggered when a marker receives focus
onBlurTriggered when a marker loses focus
onDoubleSliderCreateTriggered when the double slider is created

The Double Slider component provides the following API methods:

Gets or sets the current values of the double slider.

// Get current values
const slider = Metro.getPlugin('#mySlider', 'double-slider');
const values = slider.val();
console.log(values); // Returns [minValue, maxValue]
// Set new values
slider.val(20, 80);

Updates the slider values based on the data-value-min and data-value-max attributes.

// Update the data attributes
$('#mySlider').attr('data-value-min', 30);
$('#mySlider').attr('data-value-max', 70);
// Apply the new values
const slider = Metro.getPlugin('#mySlider', 'double-slider');
slider.changeValue();

Disables the double slider.

const slider = Metro.getPlugin('#mySlider', 'double-slider');
slider.disable();

Enables the double slider.

const slider = Metro.getPlugin('#mySlider', 'double-slider');
slider.enable();

Toggles between enabled and disabled states.

const slider = Metro.getPlugin('#mySlider', 'double-slider');
slider.toggleState();

The Double Slider component can be styled using the following CSS variables:

VariableDefault (Light)Dark ModeDescription
--slider-thumb-size18px18pxSize of the slider markers
--slider-thumb-colorvar(—color-blue)var(—color-crimson)Color of the slider markers
--slider-bar-color#191919#191919Color of the slider bar
--slider-back-color#d5d5d5#4e5055Background color of the slider track
--slider-fill-colorvar(—color-cyan)#ff145cColor of the selected range between markers
--slider-thumb-border-colorvar(—color-light-cyan)#ffffffBorder color of the slider markers
/* Custom styling for a specific double slider */
#myCustomDoubleSlider {
--slider-back-color: #e0f7fa;
--slider-fill-color: #00acc1;
--slider-thumb-color: #0097a7;
--slider-thumb-border-color: #006064;
}
  • .slider - The main slider container
  • .backside - The background track of the slider
  • .complete - The filled portion between the two markers
  • .marker - The draggable markers
  • .marker-min - The minimum value marker
  • .marker-max - The maximum value marker
  • .hint - The value hint that appears when dragging
  • .hint-min - The minimum value hint
  • .hint-max - The maximum value hint
  • .slider-min-max - Container for min/max labels
  • .slider-text-min - The minimum value label
  • .slider-text-max - The maximum value label

The Double Slider component includes proper semantics for improved accessibility:

  • Markers are implemented as <button> elements for proper keyboard focus
  • Appropriate ARIA attributes are applied
  • Disabled state is properly conveyed
  1. Always provide clear min and max values that make sense for your data range
  2. Consider using hints to show the exact values when precision is important
  3. Use appropriate accuracy settings based on your data type (e.g., 0 for integers, 0.01 for currency)
  4. Provide visual feedback through custom styling to make the selected range clear
  5. Consider using the target option to display the selected range values in a more prominent location