Skip to content

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
basic.svelte
<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
with-showvalue.svelte
<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
value-label-on-the-left.svelte
<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
with-ticks.svelte
<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
disabled.svelte
<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
custom-formatter.svelte
<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

NameTypeDefaultDescription
valuerequirednumber—Current slider value
onchangerequired(value: number) => void—Called with the new value on input
minnumber—Minimum value (ignored when ticks are provided)
maxnumber—Maximum value (ignored when ticks are provided)
stepnumber—Step increment (ignored when ticks are provided)
ticksSliderTick[]—Predefined snap points with labels
size"sm" | "md"'sm'Track height
showValuebooleanfalseDisplay 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)
disabledbooleanfalsePrevents interaction
classClassValue—Additional CSS classes
stylestring—Inline styles on the component styling target described below.
idstring—Element id
namestring—Form field name
elementbindableHTMLInputElement—Bindable reference to the range input

…rest: Forwarded to the native range input (e.g. aria-valuetext).

Usage tips

  • When ticks are provided, the slider snaps to tick values and uses the tick label for display.
  • Use valueFormatter for 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.

Documentation is licensed under CC BY 4.0. Phoundry names and marks remain reserved.