Authors:Becky Gibson, Doug Hays, Nikolai Onken


A dijit/form/HorizontalSlider is a scale with a handle you can drag left/right to select a value.


require(["dijit/form/HorizontalSlider", "dojo/domReady!"], function(HorizontalSlider){
    var slider = new HorizontalSlider({}, "mySlider").startup();

Here are some of the constructor parameters:

Parameter Type Description
value integer Initial value of the slider (0)
showButtons boolean Whether to show or not buttons at each end of the slider (true)
minimum integer Minimum value of the slider (0)
maximum integer Maximum value of the slider (100)
discreteValues integer Number of “steps” in the slider. For example if discreteValues is 3, you’ll have 3 steps: minimum, maximum and a value in the middle


Programmatic example of a horizontal slider

One way you could show the user the value of your slider is to create a textbox that the slider fills when the user moves the slider. The following code fills in a simple textbox called sliderValue.

    "dojo/dom", // for inserting value in TextBox example
    "dojo/parser", // parser because of TextBox decoration
    "dijit/form/TextBox" // this we only include to make an example with TextBox
], function(dom, parser, HorizontalSlider, TextBox){


    var slider = new HorizontalSlider({
        name: "slider",
        value: 5,
        minimum: -10,
        maximum: 10,
        intermediateChanges: true,
        style: "width:300px;",
        onChange: function(value){
            dom.byId("sliderValue").value = value;
    }, "slider").startup();
<div id="slider"></div>
<p><input type="text" id="sliderValue" data-dojo-type="dijit/form/TextBox" /></p>

Declarative markup example with discrete values

And here we create a slider declaratively. Note that we set the value of the “discreteValues” attribute to 11, meaning that the slider will have 11 focus points. This example also shows the end buttons removed.

require(["dojo/parser", "dijit/form/HorizontalSlider", "dijit/form/HorizontalRule", "dijit/form/HorizontalRuleLabels"]);
<div id="horizontalSlider"
    minimum: -10,
    <ol data-dojo-type="dijit/form/HorizontalRuleLabels" container="topDecoration"
        <li> </li>
        <li> </li>
    <div data-dojo-type="dijit/form/HorizontalRule" container="bottomDecoration"
        count=11 style="height:5px;"></div>
    <ol data-dojo-type="dijit/form/HorizontalRuleLabels" container="bottomDecoration"



Action Key
Interact with the slider The slider handle is in the tab order of the page. Press tab key to set focus to the slider handle.
Increase slider value by single increment With focus on slider handle press right or up arrow.
Decrease slider value by single increment With focus on slider handle press left or down arrow.
Increase slider value by multiple increments With focus on slider handle press PageUp. The amount of increment is determined by the pageIncrement parameter.
Decrease slider value by multiple increments With focus on slider handle press PageDown. The amount of decrement is determined by the pageIncrement parameter.
Set slider to minimum value With focus on slider handle press Home.
Set slider to maximum value With focus on slider handle press End.

Known Issues

Currently the text labels of a slider are not spoken by screen readers. Firefox 3 provides the infrastructure necessary for spoken text labels so the slider will be updated to support them in a future Dojo release. Developers should take care when using text labels since a screen reader user will hear only a numeric interpretation.

Error in the documentation? Can’t find what you are looking for? Let us know!