Range

A native <input type="range"> styled with the colour system: filled track, thumb, five sizes, any palette colour or :accent, light and dark mode.

Key Features

  • Native input - Keyboard, touch and form submission come from the browser
  • Live value - show_value: true with an optional unit:
  • 5 Sizes - xs, sm, base, lg, xl
  • All Colors - Semantic, palette, or :accent driven by CSS variables
  • Form Builder - f.rui_range reads the value and errors from the model
  • Works without JavaScript - The server renders the value, aria-valuetext and fill

Basic Usage

Pass the input name first. Set min, max and step as needed (defaults 0, 100, 1).

Basic Usage
<%= rui_range("opacity", value: 40, min: 0, max: 100, step: 5, label: "Opacity") %>

Sizes

Five sizes: :xs, :sm, :base (default), :lg, :xl.

Sizes
<%= rui_range("a", size: :xs) %>
<%= rui_range("b", size: :sm) %>
<%= rui_range("c", size: :base) %>
<%= rui_range("d", size: :lg) %>
<%= rui_range("e", size: :xl) %>

Colors

:primary (default) is near black in light mode and light grey in dark mode. Any other colour uses its 600 shade in light mode and 400 in dark mode.

Colors
<%= rui_range("a", color: :success) %>
<%= rui_range("b", color: :danger) %>
<%= rui_range("c", color: :sky) %>

Accent Colour

color: :accent follows the --rui-accent CSS variable, like buttons, links and badges. The demo sets it to orange on its wrapper. See Accent colour from CSS variables in the Button docs for the full variable list.

Accent
<%= rui_range("volume", color: :accent) %>
CSS
:root { --rui-accent: #ff6b1a; }

Live Value and Unit

show_value: true puts the current value beside the label and keeps it in sync while dragging. unit: is appended to the shown value and to aria-valuetext.

Live Value
<%= rui_range("opacity", value: 40, label: "Opacity", show_value: true, unit: "%") %>
<%= rui_range("size", value: 16, min: 8, max: 48, label: "Font size", show_value: true, unit: " px") %>

Min, Max and Step

  • min 0, max 100, step 1 by default. Decimals work.
  • With no value: the model value is used, then the midpoint (the browser default). Values are clamped into min..max.
  • max must be above min; otherwise the slider uses min + 100 and warns in development.
Decimal Step
<%= rui_range("speed", value: 1, min: 0.5, max: 2, step: 0.25, label: "Playback speed", show_value: true, unit: "x") %>

Hint, Required, Disabled

Higher is faster

States
<%= rui_range("speed", label: "Speed", help_text: "Higher is faster", required: true) %>
<%= rui_range("speed", label: "Speed", disabled: true) %>

Error

In a form, a server-side error on the attribute renders below the slider (role="alert"), turns the slider red and sets aria-invalid and aria-describedby.

Error
<%# @track.errors[:volume] is rendered for you %>
<%= form_with(model: @track) do |f| %>
  <%= f.rui_range(:volume, min: 0, max: 100, label: "Volume", show_value: true) %>
<% end %>

Form Builder

f.rui_range takes the name, id and value from the model.

Form Builder
<%= form_with(model: @track) do |f| %>
  <%= f.rui_range(:volume, min: 0, max: 11, label: "Volume", show_value: true) %>
<% end %>

Styling

Pass class: to add or override classes on the <input> (merged with Tailwind Merge, so class: "w-48" replaces w-full). Pass wrapper_class: for the outer <div>. Other options become HTML attributes on the input.

The filled part and thumb read --rui-range-color; the unfilled track reads --rui-range-track. Override them with a class for a one-off colour.

Styling
<%= rui_range("tint", class: "w-48 [--rui-range-color:#ff6b1a]") %>

Accessibility

  • The <label> is linked with for; * marks required.
  • aria-valuetext carries the value with its unit ("40%"), updated while dragging.
  • The live value is an <output aria-hidden="true"> so screen readers hear the input once, not twice.
  • Keyboard: arrows, Home, End, Page Up and Page Down (native behaviour). Focus shows a ring around the thumb.
  • Errors use role="alert" with aria-invalid and aria-describedby.

API Reference

rui_range

Styled native range slider with optional live value

Parameter Type Default Description
name_or_method* String/Symbol — Input name (standalone) or attribute (form builder)
value Numeric — Current value; falls back to the model value, then the midpoint. Clamped into min..max

Values

Bounds and increment

Parameter Type Default Description
min Numeric 0 Lowest value
max Numeric 100 Highest value. Must be above min, otherwise min + 100 is used and development warns
step Numeric 1 Increment. Decimals work

Appearance

Visual styling options

Parameter Type Default Description
color Symbol :primary Filled part and thumb colour: semantic, palette or :accent (follows --rui-accent)
size Symbol :base Slider size
:xs :sm :base :lg :xl
class String — Classes merged onto the input with Tailwind Merge
wrapper_class String — Classes for the outer div

Labels & Value

Text and live value options

Parameter Type Default Description
label String — Label text
help_text String — Hint below the slider
show_value Boolean false Live value beside the label, kept in sync by the range Stimulus controller
unit String — Appended to the shown value and aria-valuetext, e.g. "%" or " px"

States

State options

Parameter Type Default Description
required Boolean false Required marker and attribute
disabled Boolean false Disabled state
**options Hash — Other HTML attributes on the input

Related Components