---
title: BoldSlider
description: Pick a single value on a filled track that shows its label and value inline.
package: moraine
version: 0.11.0
repository: https://github.com/subframe7536/moraine
---

# BoldSlider

> Pick a single value on a filled track that shows its label and value inline.

## Anatomy

```text
BoldSlider [component; slot=root]
├── track [slot]
│   ├── range [slot]
│   └── marker [slot]
├── thumb [slot]
├── content [slot]
│   ├── label [slot]
│   └── value [slot]
└── indicator [slot]
```

## Usage

Use BoldSlider for dense settings such as inspector panels and animation controls, where each row
holds one number and the track doubles as its readout. Use [Slider](https://moraine.subf.dev/components/slider.md) for
ranges, vertical layouts, or a thin track with a visible thumb.

```tsx
import { BoldSlider } from 'moraine'

export function Example() {
  return <BoldSlider label="Opacity" defaultValue={80} valueLabel={({ value }) => `${value}%`} />
}
```

BoldSlider is built on Slider, so `value`, `defaultValue`, `onValueChange`, `onValueCommit`, `min`,
`max`, `step`, `markers`, `reversed`, form props, keyboard interaction, and `translations` behave the
same way. The value is always a single `number`; BoldSlider has no range or multi-thumb mode. `size`
accepts `sm`, `md` (default), or `lg`.

### Label and value

`label` is drawn at the start of the track; a string label is also the default `aria-label`. The
value is drawn at the end; set `valueLabel={false}` to hide it. By default the value is rounded to
the decimal places of `step` (two places without `step`) and has no digit grouping. Set
`formatOptions` to format it with `Intl.NumberFormat` instead. Pass a function to `valueLabel` to add
units or other formatting. It receives `{ percent, value, max }`, the same shape as Progress
`valueLabel`. `percent` is the filled share of the track from 0 to 100, and `max` is 100 when unset.

Both texts are drawn twice: once over the track and once clipped to the filled range. Each part of
the text uses the colors of the surface behind it, so it stays readable while the fill passes
through it. Pass a JSX `label` inline rather than as a shared node, so each layer gets its own copy.

### Variants

The default `variant="subtle"` uses a solid neutral fill, like the controls in an inspector panel.
The label, value, and indicator keep the same colors over the fill and the track. Set
`variant="solid"` for a primary-colored fill; the label, value, and indicator then switch to
`primary-foreground` where the fill passes under them.

```tsx
<BoldSlider variant="solid" label="Bounce" defaultValue={0.5} max={1} step={0.1} />
```

### Step and markers

Set `step` to snap pointer and keyboard input to increments. Without `step`, pointer movement is
continuous and arrow keys move by 1% of the range. Set `markers` to `true` to draw a tick at each
step (this requires a `step` greater than 0), or to a number to draw a tick every that many units
without changing how the value snaps. Ticks use `muted-foreground`, so they stay visible in light
and dark themes.

### Indicator

The indicator is a capsule just inside the edge of the fill. When the value is 0, the fill is hidden
and the indicator rests at the minimum-fill position as a drag anchor. Once the value is greater than
0, the fill appears and the indicator sits just inside its edge. Where it sits on the fill it uses
`--bs-indicator-fill`, and where it sits on the track it uses `--bs-indicator-track`, so its color
follows the surface behind it. It stays dim and shorter at rest, and brightens to full size while
the track is hovered, the slider is dragged, or the thumb has keyboard focus. Clicking the track
focuses the thumb without the keyboard focus ring.

These states use `peer-*` selectors on the track and thumb, so each slider reacts only to its own
interaction, even inside a parent with a `group` class.

## Examples

### Tune animation settings

Stack several sliders to build a compact control panel.

```tsx
import { BoldSlider } from 'moraine'
import { createSignal } from 'solid-js'

export function ControlPanel() {
  const [bounce, setBounce] = createSignal(0.5)
  const [stiffness, setStiffness] = createSignal(120)
  const [delay, setDelay] = createSignal(0)

  return (
    <div class="max-w-sm w-full space-y-2">
      <BoldSlider
        label="Bounce"
        value={bounce()}
        onValueChange={setBounce}
        min={0}
        max={1}
        step={0.1}
        markers
      />
      <BoldSlider
        label="Stiffness"
        value={stiffness()}
        onValueChange={setStiffness}
        min={0}
        max={300}
        step={10}
      />
      <BoldSlider
        label="Delay"
        value={delay()}
        onValueChange={setDelay}
        min={0}
        max={2000}
        step={50}
        valueLabel={({ value }) => `${value}ms`}
      />
    </div>
  )
}
```

### Show a unit with the value

Use `valueLabel` to append a unit.

```tsx
import { BoldSlider } from 'moraine'
import { createSignal } from 'solid-js'

export function BlurSlider() {
  const [value, setValue] = createSignal(32)

  return (
    <div class="max-w-md w-full">
      <BoldSlider
        label="Blur"
        value={value()}
        onValueChange={setValue}
        min={0}
        max={100}
        step={1}
        size="lg"
        valueLabel={({ value }) => `${value}px`}
      />
    </div>
  )
}
```

### Map steps to preset names

`valueLabel` can return any string, so snapped steps can read as names instead of numbers.

```tsx
import { BoldSlider } from 'moraine'
import { createSignal } from 'solid-js'

const PRESETS = ['Low', 'Medium', 'High', 'Ultra']

export function QualitySlider() {
  const [value, setValue] = createSignal(2)

  return (
    <div class="max-w-md w-full">
      <BoldSlider
        label="Quality"
        value={value()}
        onValueChange={setValue}
        min={0}
        max={3}
        step={1}
        markers
        valueLabel={({ value }) => PRESETS[value] ?? String(value)}
      />
    </div>
  )
}
```

### Bind brightness to a form

Place the slider in `form.Field` so the schema owns the committed number.

```tsx
import { BoldSlider, Button, createForm } from 'moraine'
import * as v from 'valibot'

export function FormIntegration() {
  const form = createForm({
    schema: v.object({
      brightness: v.pipe(v.number(), v.minValue(20, 'Brightness must be at least 20%.')),
    }),
    initialInput: { brightness: 60 },
    validate: 'input',
  })

  return (
    <form.Form>
      <div class="max-w-sm space-y-4">
        <form.Field name="brightness" label="Brightness" description="Keep it at least 20%.">
          <BoldSlider defaultValue={60} step={5} valueLabel={({ value }) => `${value}%`} />
        </form.Field>
        <Button type="submit" variant="soft" tone="neutral" size="sm">
          Validate
        </Button>
      </div>
    </form.Form>
  )
}
```

## API Reference

### Attributes

| Attributes | Slot | Description |
| --- | --- | --- |
| `data-fill` | `bold-slider-label`, `bold-slider-value` | — |

### Props

Props for the BoldSlider component.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| defaultValue | number \| undefined | — | The initial value (uncontrolled), with the same number or array shape as `value`; its shape<br>also sets the shape that `onValueChange` and `onValueCommit` receive. Defaults to `min`. |
| disabled | boolean \| undefined | false | Whether the control is disabled: it cannot be interacted with and sets `aria-disabled`.<br>When omitted, the control inherits `disabled` from the surrounding `Field`; an explicit<br>`false` overrides the `Field`. |
| form | string \| undefined | — | The id of a `<form>` the hidden inputs belong to, instead of the closest<br>ancestor form. |
| formatOptions | Intl.NumberFormatOptions \| undefined | — | `Intl.NumberFormat` options used to format values for `aria-valuetext`, such as<br>`{ style: 'percent' }`. Formatting uses the provider locale and does not change the<br>value passed to callbacks; `BoldSlider` also uses it for its displayed value. Remember that a<br>`percent` style multiplies by 100, so pair it with a `0`-`1` range. |
| id | string \| undefined | — | The ID of the control's main focusable element, which a surrounding `Field` label points to<br>with `for`. A unique ID is generated when omitted. The control's related parts (hidden<br>input, label, description) derive their IDs from it, so keep it unique on the page. |
| inputRef | Ref<HTMLInputElement> \| undefined | — | Receives the hidden `<input type="range">` of the first thumb. |
| label | JSX.Element \| undefined | — | Content shown at the start of the track. Also used as the default `aria-label` when it is a<br>string. It renders in both the track and fill text layers, so pass JSX inline rather than a<br>shared node. |
| markers | boolean \| number \| undefined | false | Visual markers on the track. `true` marks every `step` and needs a `step` greater than 0.<br>A number marks every that many units without affecting snapping. |
| max | number \| undefined | 100 | Maximum value of the slider. |
| min | number \| undefined | 0 | Minimum value of the slider. |
| name | string \| undefined | — | The name of the control, used for native form submission. When omitted, the control uses<br>the name of its form binding or a string `name` set on the surrounding `Field`. |
| onValueChange | ((value: number) => void) \| undefined | — | Called on every value change during interaction (pointer drag, track click, or key press),<br>with the new value in the same shape as `value`. Does not fire for programmatic changes to<br>`value`. Use `onValueCommit` to react once per finished interaction. |
| onValueCommit | ((value: number) => void) \| undefined | — | Called once an interaction that changed the value finishes: when the pointer is released,<br>when a navigation key is released, or when focus leaves the slider. Receives the final value in<br>the same shape as `value`. |
| readOnly | boolean \| undefined | false | Whether the control is read-only: the value is visible and focusable but cannot be changed,<br>and `aria-readonly` is set. When omitted, the control inherits `readOnly` from the<br>surrounding `Field`. |
| required | boolean \| undefined | false | Whether the control is required, which sets `aria-required` (and the native `required`<br>attribute where the control renders a native input). When omitted, the control inherits<br>`required` from the surrounding `Field`. |
| reversed | boolean \| undefined | false | Reverses the track direction, so `min` sits at the right (or top when vertical) instead of<br>the left (or bottom) in left-to-right layouts. |
| size | 'sm' \| 'md' \| 'lg' \| undefined | 'md' | Visual size of the component. |
| step | number \| undefined | — | Step increment between values; pointer and keyboard values snap to multiples of it from `min`.<br>When omitted (or not above `0`), pointer movement is continuous and arrow keys move by 1% of<br>the range. `PageUp`/`PageDown` and `Shift` + arrow move by about 10% of the range. |
| thumbAlignment | 'contain' \| 'overflow' \| undefined | 'overflow' | Visual alignment of the thumb at the track ends.<br>`'overflow'` centers the thumb on the value so half of it extends past<br>the track at `min` and `max`. `'contain'` clamps the thumb inside the<br>track so its edges stay within bounds. Value mapping is unaffected. |
| translations | Translations \| undefined | — | Localized message overrides for this slider instance: `thumb` returns each thumb's<br>`aria-label` and `valueText` returns its `aria-valuetext`. |
| value | number \| undefined | — | The current value (controlled). A number renders one thumb and an array renders one thumb per<br>entry (an empty array gives one thumb at `min`). Values are clamped to `min`-`max` and<br>arrays are sorted. Leave it `undefined` for uncontrolled usage. The slider throws a<br>`RangeError` when `max` is not greater than `min`. |
| valueLabel | boolean \| ((props: { percent: number; value: number; max: number }) => string) \| undefined | true | Controls the value text shown at the end of the track. `false` hides it, `true` shows the<br>number, and a function returns the text to show. The function receives the current `value`,<br>the `max` (100 when not set), and `percent`, the filled share of the track from 0 to 100.<br>With `true`, the value is formatted with `formatOptions` when set; otherwise it is rounded to<br>the decimal places of `step` (2 places without `step`) with no digit grouping. |
| variant | 'solid' \| 'subtle' \| undefined | 'subtle' | Fill treatment. `subtle` uses a solid neutral fill (`muted-active`), so the label, value, and<br>indicator keep the same colors over the fill and the track. `solid` uses the primary color<br>and switches the label, value, and indicator to `primary-foreground` over the fill. |
| class | SlotClassValue \| undefined | — | Class applied to the component root or trigger element. |
| classes | Classes \| undefined | — | Family slot class defaults for this instance. |
| style | SlotStyleValue \| undefined | — | Style applied to the component root or trigger element. |
| styles | Styles \| undefined | — | Family slot style defaults for this instance. |

**`formatOptions` example**

```tsx
import { Slider } from 'moraine'

<Slider
  defaultValue={0.25}
  min={0}
  max={1}
  step={0.05}
  formatOptions={{ style: 'percent' }}
/>
```

**`onValueCommit` example**

```tsx
import { Slider } from 'moraine'

<Slider
  defaultValue={[20, 80]}
  onValueCommit={(range) => console.log(`${range[0]} to ${range[1]}`)}
/>
```

**`translations` example**

```tsx
import { Slider } from 'moraine'

<Slider
  defaultValue={[20, 80]}
  translations={{
    thumb: ({ index }) => (index === 0 ? 'Minimum price' : 'Maximum price'),
  }}
/>
```

**`valueLabel` example**

```tsx
import { BoldSlider } from 'moraine'

<BoldSlider
  label="Volume"
  defaultValue={40}
  valueLabel={({ value, max }) => `${value} / ${max}`}
/>
```
