Range
Use our custom range inputs for consistent cross-browser styling with a filled track, value bubble, and tick marks.
Overview
The native <input type="range"> is hard to style and can’t show a filled track in a consistent, cross-browser way using CSS alone—only Firefox offers ::-moz-range-progress, and CSS can’t read an input’s value. So our range is a small JavaScript component: use FormRange, which wraps a native range input, and the plugin keeps a --bs-range-fill custom property (0–1) in sync, which the CSS uses to draw the fill, the value bubble, and tick marks.
FormRange owns the component's theme tokens, so the input and any decorations inherit them. Each mounted component initializes automatically.
<>
<FormLabel htmlFor="range1">
Example range
</FormLabel>
<FormRange id="range1" />
</>Theme colors
Set the theme prop on FormRange to change the track fill and thumb color.
<Stack gap={3}>
<FormRange
aria-label="Example primary range"
theme="primary"
/>
<FormRange
aria-label="Example accent range"
theme="accent"
/>
<FormRange
aria-label="Example secondary range"
theme="secondary"
/>
<FormRange
aria-label="Example success range"
theme="success"
/>
<FormRange
aria-label="Example danger range"
theme="danger"
/>
<FormRange
aria-label="Example warning range"
theme="warning"
/>
<FormRange
aria-label="Example info range"
theme="info"
/>
<FormRange
aria-label="Example dark range"
theme="dark"
/>
<FormRange
aria-label="Example light range"
theme="light"
/>
<FormRange
aria-label="Example inverse range"
theme="inverse"
/>
</Stack>Disabled
Add the disabled boolean attribute on the input to give it a grayed out appearance, remove pointer events, and prevent focusing.
<>
<FormLabel htmlFor="disabledRange">
Disabled range
</FormLabel>
<FormRange
disabled
id="disabledRange"
/>
</>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.
<>
<FormLabel htmlFor="range2">
Example range
</FormLabel>
<FormRange
id="range2"
max="5"
min="0"
/>
</>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".
<>
<FormLabel htmlFor="range3">
Example range
</FormLabel>
<FormRange
id="range3"
max="5"
min="0"
step="0.5"
/>
</>Value bubble
Set bubble to show a value bubble that follows the thumb. The bubble reuses our tooltip styles.
<>
<FormLabel htmlFor="rangeBubble">
Brightness
</FormLabel>
<FormRange
bubble
defaultValue="60"
id="rangeBubble"
max="100"
min="0"
/>
</>Tick marks
Link a <datalist> to the input with the list attribute and the plugin renders a tick mark for each <option>, positioned at its value (even when the values are unevenly spaced). An <option>’s label is shown beneath its tick.
<>
<FormLabel htmlFor="rangeTicks">
Temperature
</FormLabel>
<FormRange
defaultValue="50"
id="rangeTicks"
list="rangeTicksList"
max="100"
min="0"
step="25"
/>
<datalist id="rangeTicksList">
<option
label="Cold"
value="0"
/>
<option value="25" />
<option
label="Mild"
value="50"
/>
<option value="75" />
<option
label="Hot"
value="100"
/>
</datalist>
</>With form field
Wrap FormRange in FormField to pair it with a label and description.
<FormField>
<FormLabel htmlFor="rangeField">
Volume
</FormLabel>
<FormRange
bubble
id="rangeField"
/>
<FormText>
Adjust the volume level.
</FormText>
</FormField>Usage
FormRange initializes and disposes the plugin automatically. Pass bubble and formatter as props, and use onValueChange for numeric updates. Native value and defaultValue control the input value.
Each FormRange is initialized automatically when mounted—the component is JavaScript-driven, so the fill won’t render without the plugin.
Options
| Name | Type | Default | Description |
|---|---|---|---|
bubble | boolean | false | Show a value bubble above the thumb. |
formatter | function | null | (value) => string used for the bubble and tick label text. |
CSS
Variables
.example {
--bs-range-track-width: 100%;
--bs-range-track-height: 0.5rem;
--bs-range-track-cursor: pointer;
--bs-range-track-bg: var(--bs-bg-3);
--bs-range-track-border-radius: 1rem;
--bs-range-track-fill-bg: var(--bs-theme-bg, var(--bs-primary-base));
--bs-range-track-disabled-bg: color-mix(in oklch, var(--bs-bg-4), var(--bs-fg-3));
--bs-range-thumb-width: 1rem;
--bs-range-thumb-height: var(--bs-range-thumb-width);
--bs-range-thumb-bg: var(--bs-theme-bg, var(--bs-primary-base));
--bs-range-thumb-border: var(--bs-range-thumb-bg) solid var(--bs-border-color);
--bs-range-thumb-border-radius: 1rem;
--bs-range-thumb-box-shadow: 0 1px 2px rgb(0 0 0 / 7.5%), 0 2px 4px rgb(0 0 0 / 7.5%);
--bs-range-thumb-active-bg: color-mix(
in oklch,
var(--bs-theme-bg, var(--bs-primary-base)) 70%,
var(--bs-bg-body)
);
--bs-range-thumb-disabled-bg: var(--bs-fg-3);
--bs-range-thumb-transition-property: background-color, border-color, box-shadow;
--bs-range-thumb-transition-duration: 0.15s;
--bs-range-thumb-transition-timing: ease-in-out;
--bs-range-tick-width: var(--bs-border-width);
--bs-range-tick-height: 0.5rem;
--bs-range-tick-bg: var(--bs-border-color);
}