ons-range

Range input component. Used to display a draggable slider. Works very similar to the <input type="range"> element.

Tutorial

Range sliders

The <ons-range> element is used to display a slider.

There are several attributes that can be used to customize the behavior of the element. Most of these are the same attributes as those that can be used for <input type="range"> elements.

To set the maximum and minimum and maximum value the min and max attributes are used. The step attribute can be used to change how much the value changes every step.

The element can be disabled using the disabled attribute.

Getting the value

To get the current value of the slider you need to get a reference to the DOM element and read the value property.

var range = document.getElementById('range-1');
ons.notification.alert('Value is ' + range.value);

See also

Attributes are added directly to the element. You can do this in HTML or JS.

HTML: <ons-range someAttribute="true" anotherAttribute><ons-range>
JS: document.querySelector('ons-range').setAttribute('someAttribute', 'true')

Name Type Description
disabled Whether the element is disabled or not. Optional.

Properties are accessed on the element through JS, and should be get and set directly. For example: document.querySelector('ons-range').disabled.

Name Description
disabled Whether the element is disabled or not.
value Current value.

Modifiers are set in the modifier attribute. To use more than one, separate them by spaces. For example:
<ons-range modifier="material modifier2"><ons-range>.

Name Description
material Material Design slider

These methods are called directly on the DOM element. Get a reference to the element in JS, and the methods below will be available to call on it. For example: document.querySelector('ons-range').someMethod().

Signature Description
focus() Focuses the range.
blur() Removes focus from the range.
focus()

Focuses the range.

blur()

Removes focus from the range.

Need Help?

If you have any questions, use our Community Forum or talk to us on Discord chat. The Onsen UI team and your peers in the community will work together to help solve your issues.

For bug reports and feature requests use our GitHub Issues page.