Bootstrap 5 Range
A range input (<input type="range">) is a slider for choosing a number between a minimum and a maximum — volume, brightness, price limit. Browsers draw sliders in wildly different ways; the .form-range class gives them a consistent Bootstrap look with a theme-coloured thumb.
Basic range
html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<label for="volume" class="form-label">Volume</label>
<input type="range" class="form-range" id="volume">
<label for="locked" class="form-label">Disabled</label>
<input type="range" class="form-range" id="locked" disabled>
</body>
</html>By default a range goes from 0 to 100 in steps of 1, starting in the middle (50).
Min, max and step
| Attribute | Default | Meaning |
|---|---|---|
min |
0 |
Lowest value |
max |
100 |
Highest value |
step |
1 |
Increment (e.g. 0.5, 5) |
value |
middle of the range | Starting value |
disabled |
— | Can't be moved |
html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<label for="rating" class="form-label">Rating: 1 to 5</label>
<input type="range" class="form-range" min="1" max="5" step="1" value="3" id="rating">
<label for="temp" class="form-label">Temperature: 15 to 30 °C in half degrees</label>
<input type="range" class="form-range" min="15" max="30" step="0.5" value="21.5" id="temp">
<script>
for (const id of ['rating', 'temp']) {
document.getElementById(id).addEventListener('change', (e) => console.log(id, '=', e.target.value));
}
</script>
</body>
</html>The change event fires when the user lets go of the thumb; input fires continuously while dragging.
Showing the current value
A range doesn't show its number by itself. Use the input event to display it live, for example in a badge or an <output> element.
html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="d-flex justify-content-between">
<label for="price" class="form-label">Max price</label>
<output for="price" id="priceOut" class="badge text-bg-primary align-self-start">$250</output>
</div>
<input type="range" class="form-range" min="0" max="500" step="10" value="250" id="price">
<div class="d-flex justify-content-between small text-body-secondary"><span>$0</span><span>$500</span></div>
<div class="mt-4 p-3 rounded text-center fs-4" id="preview" style="background: hsl(260, 60%, 50%); color: #fff;">Hue 260</div>
<input type="range" class="form-range" min="0" max="360" value="260" id="hue" aria-label="Hue">
<script>
const price = document.getElementById('price');
price.addEventListener('input', () => {
document.getElementById('priceOut').textContent = '