Web Component

Input Range

An input where the user selects a value from within a given range.

Table of contents

Usage

Input Range is a web component built from scratch to enable users to easily integrate customizable range sliders. With built-in support for keyboard navigation, ARIA attributes for accessibility, and a minimalist design.

To get started, simply use the <uk-input-range> markup in your HTML code.

Dual range

To enable dual range functionality (allowing you to select a range with both a minimum and maximum value), simply add the multiple attribute to your <uk-input-range> element. When this attribute is present, the component renders two knobs: one for the minimum value and one for the maximum value.

Capturing values

There are several ways to capture values from the <uk-input-range> component. The simplest approach is to add a name attribute to the component. When you do this, a hidden input field with the specified name will be automatically generated, allowing you to easily capture the selected value on your server.

Note When using the dual knob mode by including the multiple attribute, the component renders two hidden input fields—one for the lower value and one for the upper value. In this case, the name attribute is automatically appended with [] (e.g., name="range[]") to indicate an array of values. This makes it straightforward to process both values on the server side.

Prepopulating values

Prepopulating the Input Range component is straightforward. Simply pass a value (or values) via the value attribute when declaring the component in your HTML. This is particularly useful when you need to display existing data that users can adjust or confirm.

Note When using the dual knob mode, supply two values separated by a comma. The first value sets the lower bound, and the second value sets the upper bound.

Labeling

The label attribute allows you to display a label on each knob of the slider. This label can be used to show the current numeric value, or a custom text concatenated with the value.

Note If you simply include the label attribute (or set it to true), the slider will display only the numeric value. Otherwise, label will be concatenated.

Position

In addition to the label, you can control its position relative to the knob using the label-position attribute. This attribute accepts two values:

  • top (default): The label appears above the knob.
  • bottom: The label appears below the knob.

Min and max

The min and max attributes define the range boundaries of the slider. They determine the lowest and highest possible values that can be selected.

Step

The step attribute determines the interval at which the slider’s value increments or decrements. This attribute mimics the behavior of the native HTML <input type="range">, ensuring that as you drag or use keyboard navigation, the value snaps to defined increments. For example, if the step is set to 0.5, the slider will move in increments of 0.5 units, such as 0.0, 0.5, 1.0, etc.

Disable input

To prevent user input, add the disabled attribute to the <uk-input-range> element. This will disable the component, making it impossible for users to enter or modify value.

Preventing layout shift

When loading Web Components, there may be a brief delay before the content is fully rendered. This can result in a flash of unstyled content or unprocessed templates. To mitigate this issue, consider setting a predefined height on the parent element to prevent layout shift and ensure a smooth user experience.

Internationalization

The Input Range component supports internationalization through multiple methods with the following priority order (highest to lowest):

  1. Component-level i18n (via i18n attribute or script tag)
  2. Global component-specific namespace (via <script id="uk-i18n">)
  3. Default values

Using the i18n attribute

Using a configuration script

PR

Using global i18n

Place this in your document <head> or before any input-range components:

Available i18n options

KeyDefaultDescription
aria-value-textValue: {value}ARIA value text for single mode (supports {value} placeholder)
aria-range-textRange from {low} to {high}ARIA value text for multiple mode (supports {low}, {high} placeholders)
low-knob-labelMinimum valueARIA label for the low/single knob
high-knob-labelMaximum valueARIA label for the high knob (multiple mode only)
aria-labelRange sliderARIA label for the component group

Custom classes

The Input Range component supports custom CSS classes through the cls attribute. This allows you to style specific elements within the slider without modifying the component’s internal structure.

Using simple string format

Apply a class to the default element (host-inner):

Using JSON object format

Target specific elements within the input range:

Using configuration script

Available cls targets

TargetDescription
host-innerThe main container wrapper for the entire component
runnableThe track/rail element that knobs slide along
fillThe filled portion of the track (from start to knob or between knobs)
knobBase class for all knobs
knob-lowThe low/single knob (overrides knob for this knob)
knob-highThe high knob in multiple mode (overrides knob)
knob-draggingAdditional class applied to knob while being dragged
labelBase class for value labels
label-topClass applied when label-position=“top”
label-bottomClass applied when label-position=“bottom”

Custom inline styles

The Input Range component supports custom inline styles through the stl attribute. This allows you to apply specific CSS styles to individual elements within the slider.

Using simple string format

Apply styles to the default element (host-inner):

Using JSON object format

Target specific elements with custom styles:

Using configuration script

Available stl targets

The stl attribute supports the same targets as the cls attribute. See the Available cls targets table above for a complete list of targetable elements.

Attributes

The following attributes are available for this component:

NameTypeDefaultDescription
multipleBooleanfalseEnables dual-knob mode for selecting a value range
minNumber0Minimum allowed value for the slider
maxNumber100Maximum allowed value for the slider
stepNumber1Step increment for value changes
labelString/BooleanfalseShow value label on knob(s). Can be boolean (true/false) or custom text
label-positionStringtopPosition of the label relative to knob: top or bottom
aria-labelStringCustom ARIA label for the component (overrides i18n default)
nameStringName attribute for hidden input(s), enabling form submission
disabledBooleanfalseDisables the entire component, preventing user interaction
requiredBooleanfalseMarks the input as required for form validation
valueStringPre-set value (single) or comma-separated values (multiple mode)
clsStringCustom CSS classes. Can be simple string or JSON object for targeting elements
stlStringCustom inline styles. Can be simple string or JSON object for targeting elements
i18nStringInternationalization strings as JSON object or via configuration script
force-prevent-rerenderBooleanfalsePrevents component rerendering (useful for HTMX or SPA scenarios)

Events

The Input Range component triggers the following event:

NameDescription
uk-input-range:inputFired when the range value changes. Event detail contains {value: string | string[]}. In single mode, value is a string. In multiple mode, value is an array of two strings.