Range
Use our custom range inputs for consistent cross-browser styling and built-in customization.
Overview
Create custom <input type="range">
controls with .form-range
. The track (the background) and thumb (the value) are both styled to appear the same across browsers.
Progressive enhancement
Only Firefox supports “filling” their track from the left or right of the thumb as a means to visually indicate progress — so Edge, Chrome and Safari won’t show it, and it’s perfectly fine.
<label for="customRange1" class="form-label">Example range</label>
<input type="range" class="form-range" id="customRange1">
Disabled
Add the disabled
boolean attribute on an input to give it a grayed out appearance, remove pointer events, and prevent focusing.
<label for="disabledRange" class="form-label is-disabled">Disabled range</label>
<input type="range" class="form-range" id="disabledRange" disabled>
Min and max
Range inputs have implicit values for min
and max
—0
and 100
, respectively. You may specify new values for those using the min
and max
attributes.
<label for="customRange2" class="form-label">Example range</label>
<input type="range" class="form-range" min="0" max="5" id="customRange2">
Steps
By default, range inputs “snap” to integer values. To change this, you can specify a step
value. In the example below, we double the number of steps by using step="0.5"
.
<label for="customRange3" class="form-label">Example range</label>
<input type="range" class="form-range" min="0" max="5" step="0.5" id="customRange3">
Usability
For better usability, it is recommended most of the time to display the current selected value.
This requires extra JavaScript code.
<div class="d-flex w-100 justify-content-between">
<label for="customRange4" class="form-label">Example range</label>
<output for="customRange4" class="fw-bold" aria-hidden="true"></output>
</div>
<input type="range" class="form-range" min="0" max="100" step="1" id="customRange4">
<script>
// Please note that this script is only an example, please adapt it to your needs
function updateLabelValue() {
document.querySelector(`output[for="${this.id}"]`).innerHTML = this.value;
}
window.addEventListener('load', function () {
Array.from(document.getElementsByClassName('form-range')).forEach(function (el) {
if (document.querySelector(`output[for="${el.id}"]`)) {
el.addEventListener('input', updateLabelValue)
updateLabelValue.call(el)
}
})
})
</script>
CSS
Sass variables
$form-range-track-width: 100%;
$form-range-track-height: .375rem; // Boosted mod: instead of `.5rem`
$form-range-track-cursor: pointer;
$form-range-track-bg: var(--#{$prefix}secondary-bg);
$form-range-track-filled-bg: var(--#{$prefix}primary); // Boosted mod
$form-range-track-border-radius: null; // Boosted mod: instead of `1rem`
$form-range-track-box-shadow: var(--#{$prefix}box-shadow-inset);
$form-range-thumb-width: 1rem;
$form-range-thumb-height: $form-range-thumb-width;
$form-range-thumb-bg: var(--#{$prefix}body-bg); // Boosted mod: instead of `$component-active-bg`
$form-range-thumb-border: var(--#{$prefix}border-width) solid var(--#{$prefix}border-color); // Boosted mod: instead of `0`
$form-range-thumb-border-radius: 50%;
$form-range-thumb-box-shadow: 0 .1rem .25rem rgba($black, .1);
$form-range-thumb-focus-box-shadow: null; // Boosted mod
$form-range-thumb-focus-box-shadow-width: $input-focus-width; // For focus box shadow issue in Edge
$form-range-thumb-hover-bg: var(--#{$prefix}highlight-bg); // Boosted mod
$form-range-thumb-active-bg: var(--#{$prefix}primary); // Boosted mod: instead of `tint-color($component-active-bg, 70%)`
$form-range-thumb-active-border: var(--#{$prefix}primary); // Boosted mod
$form-range-thumb-disabled-bg: var(--#{$prefix}disabled-color); // Boosted mod: instead of `var(--#{$prefix}secondary-color)`
$form-range-thumb-transition: background-color $transition-duration $transition-timing, border-color $transition-duration $transition-timing; // Boosted mod: no box shadow