The Range slider lets users select from a range of values by moving the slider knob. By default one knob controls the value of the range. This behavior can be customized using dual knobs.
By default the Range slider has a minimum value of 0 and a maximum value of 100. This can be configured with the min and max properties.
Decorative elements can be passed into the start or end slots of the range. This is useful for adding icons such as low volume or high volume icons. Since these elements are decorative, they should not be announced by assistive technology such as screen readers.
If the directionality of the document is set to left to right, the contents slotted to the start position will display to the left of the range, where as contents slotted to the end position will display to the right of the range. In right to left (rtl) directionality, the contents slotted to the start position will display to the right of the range, where as contents slotted to the end position will display to the left of the range.
Dual knobs introduce two knob controls that users can use to select a value at a lower and upper bounds. When selected, the Range will emit an ionChange event with a RangeValue, containing the upper and lower values selected.
The ionKnobMoveStart event emits when the Range knob begins dragging, whether through mouse drag, touch gesture or keyboard interaction. Inversely, ionKnobMoveEnd emits when the Range knob is released. Both events emit with the RangeValue type and work in combination with the dualKnobs property.
Range includes CSS Shadow Parts to allow complete customization of specific element nodes within the Range component. CSS Shadow Parts offer the most customization capabilities and are the recommended approach when requiring advance styling with the Range component.
A simpler range syntax was introduced in Ionic 7.0. This new syntax reduces the boilerplate required to setup an range, resolves accessibility issues, and improves the developer experience.
Developers can perform this migration one range at a time. While developers can continue using the legacy syntax, we recommend migrating as soon as possible.
Using the modern syntax involves removing the ion-label and passing the label directly inside of ion-range using slot="label". The placement of the label can be configured using the labelPlacement property on ion-range.
JavaScript
Angular
React
Vue
<!-- Basic --> <!-- Before --> <ion-item> <ion-label>Notifications</ion-label> <ion-range></ion-range> </ion-item> <!-- After --> <ion-item> <ion-range> <divslot="label">Notifications</div> </ion-range> </ion-item> <!-- Fixed Labels --> <!-- Before --> <ion-item> <ion-labelposition="fixed">Notifications</ion-label> <ion-range></ion-range> </ion-item> <!-- After --> <ion-item> <ion-rangelabel-placement="fixed"> <divslot="label">Notifications</div> </ion-range> </ion-item> <!-- Range at the start of line, Label at the end of line --> <!-- Before --> <ion-item> <ion-labelslot="end">Notifications</ion-label> <ion-range></ion-range> </ion-item> <!-- After --> <ion-item> <ion-rangelabel-placement="end"> <divslot="label">Notifications</div> </ion-range> </ion-item>
<!-- Basic --> <!-- Before --> <ion-item> <ion-label>Notifications</ion-label> <ion-range></ion-range> </ion-item> <!-- After --> <ion-item> <ion-range> <divslot="label">Notifications</div> </ion-range> </ion-item> <!-- Fixed Labels --> <!-- Before --> <ion-item> <ion-labelposition="fixed">Notifications</ion-label> <ion-range></ion-range> </ion-item> <!-- After --> <ion-item> <ion-rangelabelPlacement="fixed"> <divslot="label">Notifications</div> </ion-range> </ion-item> <!-- Range at the start of line, Label at the end of line --> <!-- Before --> <ion-item> <ion-labelslot="end">Notifications</ion-label> <ion-range></ion-range> </ion-item> <!-- After --> <ion-item> <ion-rangelabelPlacement="end"> <divslot="label">Notifications</div> </ion-range> </ion-item>
{/* Basic */} {/* Before */} <IonItem> <IonLabel>Notifications</IonLabel> <IonRange></IonRange> </IonItem> {/* After */} <IonItem> <IonRange> <divslot="label">Notifications</div> </IonRange> </IonItem> {/* Fixed Labels */} {/* Before */} <IonItem> <IonLabelposition="fixed">Notifications</IonLabel> <IonRange></IonRange> </IonItem> {/* After */} <IonItem> <IonRangelabelPlacement="fixed"> <divslot="label">Notifications</div> </IonRange> </IonItem> {/* Range at the start of line, Label at the end of line */} {/* Before */} <IonItem> <IonLabelslot="end">Notifications</IonLabel> <IonRange></IonRange> </IonItem> {/* After */} <IonItem> <IonRangelabelPlacement="end"> <divslot="label">Notifications</div> </IonRange> </IonItem>
<!-- Basic --> <!-- Before --> <ion-item> <ion-label>Notifications</ion-label> <ion-range></ion-range> </ion-item> <!-- After --> <ion-item> <ion-range> <divslot="label">Notifications</div> </ion-range> </ion-item> <!-- Fixed Labels --> <!-- Before --> <ion-item> <ion-labelposition="fixed">Notifications</ion-label> <ion-range></ion-range> </ion-item> <!-- After --> <ion-item> <ion-rangelabel-placement="fixed"> <divslot="label">Notifications</div> </ion-range> </ion-item> <!-- Range at the start of line, Label at the end of line --> <!-- Before --> <ion-item> <ion-labelslot="end">Notifications</ion-label> <ion-range></ion-range> </ion-item> <!-- After --> <ion-item> <ion-rangelabel-placement="end"> <divslot="label">Notifications</div> </ion-range> </ion-item>
note
In past versions of Ionic, ion-item was required for ion-range to function properly. Starting in Ionic 7.0, ion-range should only be used in an ion-item when the item is placed in an ion-list. Additionally, ion-item is no longer required for ion-range to function properly.
Ionic uses heuristics to detect if an app is using the modern range syntax. In some instances, it may be preferable to continue using the legacy syntax. Developers can set the legacy property on ion-range to true to force that instance of the range to use the legacy syntax.
While not required, this interface can be used in place of the CustomEvent interface for stronger typing with Ionic events emitted from this component.
The start position of the range active bar. This feature is only available with a single knob (dualKnobs="false"). Valid values are greater than or equal to the min value and less than or equal to the max value.
The color to use from your application's color palette. Default options are: "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", and "dark". For more information on colors, see theming.
Where to place the label relative to the range. "start": The label will appear to the left of the range in LTR and to the right in RTL. "end": The label will appear to the right of the range in LTR and to the left in RTL. "fixed": The label has the same behavior as "start" except it also has a fixed width. Long text will be truncated with ellipses ("...").
Set the legacy property to true to forcibly use the legacy form control markup. Ionic will only opt components in to the modern form markup when they are using either the aria-label attribute or the label property. As a result, the legacy property should only be used as an escape hatch when you want to avoid this automatic opt-in behavior. Note that this property will be removed in an upcoming major release of Ionic, and all form components will be opted-in to using the modern form markup.
The ionChange event is fired for <ion-range> elements when the user modifies the element's value: - When the user releases the knob after dragging; - When the user moves the knob with keyboard arrows
ionChange is not fired when the value is changed programmatically.
ionFocus
Emitted when the range has focus.
ionInput
The ionInput event is fired for <ion-range> elements when the value is modified. Unlike ionChange, ionInput is fired continuously while the user is dragging the knob.
ionKnobMoveEnd
Emitted when the user finishes moving the range knob, whether through mouse drag, touch gesture, or keyboard interaction.
ionKnobMoveStart
Emitted when the user starts moving the range knob, whether through mouse drag, touch gesture, or keyboard interaction.