DevExtreme v24.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

JavaScript/jQuery Slider

This demo shows how you can create and configure a JavaScript Slider.

DevExtreme Accessibility Compliance
DevExtreme component libraries meet a variety of WCAG and Section 508 compliance standards. To assess this demo’s accessibility level, click the Run AXE® Validation button to launch the AXE® web accessibility evaluation tool.
All trademarks or registered trademarks are property of their respective owners. AXE® Terms of Use
The overall accessibility level of your application depends on the Slider features used.
Backend API
$(() => { $('#slider-simple').dxSlider({ min: 0, max: 100, value: 90, }); $('#slider-with-label').dxSlider({ min: 0, max: 100, value: 50, label: { visible: true, format(value) { return `${value}%`; }, position: 'top', }, }); $('#slider-with-tooltip').dxSlider({ min: 0, max: 100, value: 35, rtlEnabled: false, tooltip: { enabled: true, format(value) { return `${value}%`; }, showMode: 'always', position: 'bottom', }, }); $('#slider-with-hide-range').dxSlider({ min: 0, max: 100, value: 20, showRange: false, }); $('#slider-with-step').dxSlider({ min: 0, max: 100, value: 10, step: 10, tooltip: { enabled: true, }, }); $('#slider-disabled').dxSlider({ min: 0, max: 100, value: 50, disabled: true, }); const onHandleMoveSlider = $('#slider-on-handle-move').dxSlider({ min: 0, max: 100, value: 10, onValueChanged({ value }) { onHandleReleaseSlider.option('value', value); sliderValue.option('value', value); }, }).dxSlider('instance'); const onHandleReleaseSlider = $('#slider-on-handle-release').dxSlider({ min: 0, max: 100, value: 10, valueChangeMode: 'onHandleRelease', onValueChanged({ value }) { onHandleMoveSlider.option('value', value); sliderValue.option('value', value); }, }).dxSlider('instance'); const sliderValue = $('#slider-value').dxNumberBox({ value: 10, min: 0, max: 100, showSpinButtons: true, inputAttr: { 'aria-label': 'Slider Value' }, onValueChanged({ value }) { onHandleMoveSlider.option('value', value); onHandleReleaseSlider.option('value', value); }, }).dxNumberBox('instance'); });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/24.1.6/css/dx.light.css" /> <script src="js/dx.all.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div class="form"> <div class="dx-fieldset"> <div class="dx-field"> <div class="dx-field-label">Default mode</div> <div class="dx-field-value"> <div id="slider-simple"></div> </div> </div> <div class="dx-field custom-height-slider"> <div class="dx-field-label">With labels</div> <div class="dx-field-value"> <div id="slider-with-label"></div> </div> </div> <div class="dx-field custom-height-slider"> <div class="dx-field-label">With tooltip</div> <div class="dx-field-value"> <div id="slider-with-tooltip"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Without range highlighting</div> <div class="dx-field-value"> <div id="slider-with-hide-range"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">With discrete step</div> <div class="dx-field-value"> <div id="slider-with-step"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Disabled</div> <div class="dx-field-value"> <div id="slider-disabled"></div> </div> </div> </div> <div class="dx-fieldset"> <div class="dx-fieldset-header">Process Value Changes</div> <div class="dx-field"> <div class="dx-field-label">On handle movement</div> <div class="dx-field-value"> <div id="slider-on-handle-move"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">On handle release</div> <div class="dx-field-value"> <div id="slider-on-handle-release"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Slider value</div> <div class="dx-field-value"> <div id="slider-value"></div> </div> </div> </div> </div> </div> </body> </html>
.custom-height-slider { height: 75px; } .dx-field .dx-slider { flex: 1; }

Create a JavaScript Slider

To create a JavaScript Slider, declare it in markup and use the min and max properties to limit the range of accepted values.

You can also specify the value property to change the initial value.

The Default mode section shows a JavaScript Slider with such a basic setup.

Customize JavaScript Slider Appearance

Max and min labels

The JavaScript Slider can display labels for the min and max values. To configure the labels, use the label object. In this object, specify the visible, position, and format properties.

Tooltip

To display a handle tooltip, you need to configure the tooltip object:

  • Set the enabled property to true to display a tooltip.

  • Specify the tooltip position: over or under the JavaScript Slider.

  • Specify the format property.

  • Assign 'onHover' or 'always' to the showMode property to change how the component shows a tooltip.

Range highlight

Use the showRange property to specify if the component should highlight the range between min and value.

Discrete step

Use the step property to specify the value change step for the JavaScript Slider.

Disabled state

If you want to disable the JavaScript Slider, set the disabled property to true.

Handle the Value Change Event

Specify the onValueChanged function to handle the value change. In this demo, the NumberBox component and the Sliders use this function to exchange values.

The valueChangeMode property allows you to choose when the JavaScript Slider changes its value. Available modes include onHandleMove and onHandleRelease. You can see the property's effect in the Process Value Changes section. The first JavaScript Slider changes its value while a user slides the handle. The second JavaScript Slider changes its value only after the user releases the handle. These JavaScript Slider values are synchronized.