Slider
Range slider with optional ticks, value display, and custom formatter. Uses a native range input for full accessibility.
import { Slider } from "phoundry-ui";Basic
Loading interactive example…
View source
<script lang="ts"> import { Slider } from "phoundry-ui";
let basic = $state(50);</script>
<div class="flex items-center gap-3"> <Slider value={basic} onchange={(v: number) => (basic = v)} min={0} max={100} class="w-64" /> <span class="text-xs text-txt-tertiary">{basic}</span></div>With showValue
Loading interactive example…
View source
<script lang="ts"> import { Slider } from "phoundry-ui";
let withValue = $state(75);</script>
<Slider value={withValue} onchange={(v: number) => (withValue = v)} min={0} max={100} showValue class="w-64"/>Value label on the left
Loading interactive example…
View source
<script lang="ts"> import { Slider } from "phoundry-ui"; import type { SliderTick } from "phoundry-ui";
let valueStart = $state(2);
const fontTicks: SliderTick[] = [ { value: 10, label: "10px" }, { value: 12, label: "12px" }, { value: 14, label: "14px" }, { value: 16, label: "16px" }, { value: 18, label: "18px" }, { value: 20, label: "20px" }, ];</script>
<Slider value={valueStart} onchange={(v: number) => (valueStart = v)} ticks={fontTicks} showValue valuePosition="start" class="w-64"/>With ticks
Loading interactive example…
View source
<script lang="ts"> import { Slider } from "phoundry-ui"; import type { SliderTick } from "phoundry-ui";
let tickValue = $state(14);
const fontTicks: SliderTick[] = [ { value: 10, label: "10px" }, { value: 12, label: "12px" }, { value: 14, label: "14px" }, { value: 16, label: "16px" }, { value: 18, label: "18px" }, { value: 20, label: "20px" }, ];</script>
<Slider value={tickValue} onchange={(v: number) => (tickValue = v)} ticks={fontTicks} showValue class="w-64"/>Disabled
Loading interactive example…
View source
<script lang="ts"> import { Slider } from "phoundry-ui";
let disabledSl = $state(40);</script>
<Slider value={disabledSl} onchange={(v: number) => (disabledSl = v)} min={0} max={100} disabled showValue class="w-64"/>Custom formatter
Loading interactive example…
View source
<script lang="ts"> import { Slider } from "phoundry-ui";
let formatted = $state(0.5);</script>
<Slider value={formatted} onchange={(v: number) => (formatted = v)} min={0} max={1} step={0.01} showValue valueFormatter={(v) => `${Math.round(v * 100)}%`} class="w-64"/>API
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
valuerequired | number | — | Current slider value |
onchangerequired | (value: number) => void | — | Called with the new value on input |
min | number | — | Minimum value (ignored when ticks are provided) |
max | number | — | Maximum value (ignored when ticks are provided) |
step | number | — | Step increment (ignored when ticks are provided) |
ticks | SliderTick[] | — | Predefined snap points with labels |
size | "sm" | "md" | 'sm' | Track height |
showValue | boolean | false | Display current value next to the slider |
valuePosition | "start" | "end" | 'end' | Which side of the track shows the value label when showValue is true |
valueFormatter | (v: number) => string | (v: number) => String(v) | Custom display formatter (ignored when ticks are provided) |
disabled | boolean | false | Prevents interaction |
class | ClassValue | — | Additional CSS classes |
style | string | — | Inline styles on the component styling target described below. |
id | string | — | Element id |
name | string | — | Form field name |
elementbindable | HTMLInputElement | — | Bindable reference to the range input |
…rest: Forwarded to the native range input (e.g. aria-valuetext).
Usage tips
- When
ticksare provided, the slider snaps to tick values and uses the tick label for display. - Use
valueFormatterfor custom units (percentages, currency, etc.) on continuous sliders. - Use
style="inline-size: 16rem"to control slider length.
Styling
.ph-slider is the stable root identification hook. Styling is component-local vanilla CSS; data-size always identifies the selected size. class and style apply to the root wrapper; native attributes, attachments, and bind:element target the range input. data-value-position exposes start or end. Both sizes retain the same track geometry. Tick snapping, value formatting, and keyboard input are unchanged. Disabled controls do not respond visually to hover, and track and thumb transitions respect reduced-motion preferences. Internal part selectors and --_ph-* properties are implementation details.