Skip to content

Slider

<loomi-slider> — select a numeric value with a slider, instead of clicking increment/decrement arrows or typing a value directly. Form-associated: submits the value under name.

Terminal window
npm install @loomidev/slider lit
import "@loomidev/slider";
<loomi-slider></loomi-slider>

Give each slider on a page a unique name if you need to read its value on form submission — particularly important if there’s more than one slider on the page.

The default color is primary. Any loomi color works, and themes the native track via accent-color.

<loomi-slider selected="50" color="success"></loomi-slider>
<loomi-slider selected="30" color="warning"></loomi-slider>
<loomi-slider selected="70" color="error"></loomi-slider>

selected is also how you pre-populate the slider in edit mode.

By default the slider increments by 1. Set step for a coarser interval.

<loomi-slider selected="10" step="5"></loomi-slider>

Default bounds are 0100.

<loomi-slider min="18" max="65" selected="25"></loomi-slider>

The current value is shown in a tooltip above the slider handle and moves with it.

Add comma-separated marks for scale stops, such as a thermometer or scoring scale.

<loomi-slider min="-20" max="50" selected="22" marks="-20,0,20,37,50"></loomi-slider>

Add range for a dual-handle slider. selected controls the start value and selected-end controls the end value.

<loomi-slider name="budget" range selected="20" selected-end="80"></loomi-slider>

When submitted in a form, a range slider submits the ordered values joined with " - ".

new FormData(form).get("budget"); // "20 - 80"
<loomi-slider show-values="false"></loomi-slider>
<loomi-slider show-tooltip="false"></loomi-slider>
<loomi-slider vertical selected="40" marks="0,25,50,75,100"></loomi-slider>
<loomi-slider selected="55" handle-width="1.4rem" handle-variant="square"></loomi-slider>
<loomi-slider selected="55" track-radius="0.25rem" handle-variant="line"></loomi-slider>

Set value-target to a DOM selector when another field should mirror the slider value.

<loomi-slider selected="36" value-target="#temperature"></loomi-slider>
<input id="temperature" value="36" />
<loomi-slider name="age" selected="34"></loomi-slider>
new FormData(form).get("age"); // "34"

For the library-wide baseline, see Foundations — Accessibility.

For the shared container and viewport rules, see Foundations — Responsive behavior.

For theme activation, token overrides, and contrast guidance, see Foundations — Dark mode.

AttributeDefaultDescription
name(blank)Submitted with the form.
selected0Current/default value.
selected-end100End value when range is enabled.
rangefalseEnable dual-handle range selection. (boolean)
min0Lower bound.
max100Upper bound.
step1Increment.
colorprimaryAny loomi color (themes the track via accent-color).
show-valuestrueShow the handle value tooltip. (boolean)
show-tooltiptrueShow or hide the tooltip while keeping the value behavior. (boolean)
marks(blank)Comma-separated mark values or a JS number array.
verticalfalseRender a vertical slider. (boolean)
handle-width(blank)Custom handle width, for example 1.25rem.
handle-variantdefaultdefault, square, or line.
track-radius999pxSlider bar roundness.
value-target(blank)Selector for an input/output field to update as the slider moves.
EventDescription
changeFired when the value is committed or changed.
inputFired while the value is edited.
<loomi-slider
name="volume"
min="0"
max="100"
step="5"
selected="65"
color="success"
></loomi-slider>

<loomi-slider> is a standard custom element, so the browser can use it in plain HTML, Blade, React, Vue, Angular, Svelte, Astro, and most other frameworks. The important beginner rule is: install the package, import it once before the tag is rendered, then write the Loomi tag in your template.

Run install commands from the app where you want to use this component. That means the folder that contains that app’s package.json. Do not run these install commands from packages/slider unless you are editing LoomiUI itself.

Terminal window
cd /path/to/your-app
npm install @loomidev/slider lit

If you are contributing to LoomiUI itself, first move to the top-level components folder. That is where the main package.json for all packages lives, and pnpm --filter ... commands should be run from there:

Terminal window
cd /path/to/your-copy-of-loomiui/components
pnpm --filter @loomidev/slider build
pnpm --filter @loomidev/slider typecheck

Use the CDN version for prototypes, documentation pages, or a quick reproduction. The import map tells the browser where to find Lit, which Loomi components use internally.

<script type="importmap">
{ "imports": { "lit": "https://esm.sh/lit@3.3.3", "lit/": "https://esm.sh/lit@3.3.3/" } }
</script>
<script type="module" src="https://esm.sh/@loomidev/slider"></script>
<loomi-slider name="budget" min="0" max="100" step="5" selected="40" show-values></loomi-slider>

In Vite, Webpack, Parcel, Rollup, or a framework build pipeline, install the package and import it once in your main app JavaScript file. After that, you can use the Loomi tag anywhere in your app.

import "@loomidev/slider";

Because this is a form-capable component, give it a name when it should submit with a native <form>. Read its value with new FormData(form).get("the-name") just like you would for a built-in input.

Run the install command from your Laravel project root, then import the component in resources/js/app.js. If your project uses Laravel Vite, npm run dev and npm run build should also be run from the Laravel project root.

Terminal window
cd /path/to/your-laravel-app
npm install @loomidev/slider lit
npm run dev
resources/js/app.js
import "@loomidev/slider";
<loomi-slider name="budget" min="0" max="100" step="5" selected="40" show-values></loomi-slider>

React can render Loomi tags directly. If you are on React 18, or if you need to pass arrays, objects, or functions, use a ref and assign those values after the component mounts.

import "@loomidev/slider";
export function LoomiExample() {
return (
<loomi-slider name="budget" min="0" max="100" step="5" selected="40" show-values></loomi-slider>
);
}

If TypeScript does not recognize the Loomi tag in JSX, add it to your app’s JSX type declarations.

Import the package in the component that uses it, or once in your main Vue file. Vue templates can use Loomi tags directly. For arrays, objects, or functions, pass the value as a JavaScript property instead of as plain text.

<script setup>
import "@loomidev/slider";
</script>
<template>
<loomi-slider name="budget" min="0" max="100" step="5" selected="40" show-values></loomi-slider>
</template>

If Vue warns that the tag is an unknown component, configure compilerOptions.isCustomElement for tags that start with loomi- in your Vite or Vue config.

Import the package once and tell Angular to allow custom HTML tags with CUSTOM_ELEMENTS_SCHEMA. For NgModule apps, add the schema to the module instead of the standalone component.

app.component.ts
import { CUSTOM_ELEMENTS_SCHEMA, Component } from "@angular/core";
import "@loomidev/slider";
@Component({
selector: "app-root",
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<loomi-slider name="budget" min="0" max="100" step="5" selected="40" show-values></loomi-slider>
`,
})
export class AppComponent {}

Svelte can import the package inside a component script. Astro can import it in the frontmatter of the page or layout where the tag appears.

<script>
import "@loomidev/slider";
</script>
<loomi-slider name="budget" min="0" max="100" step="5" selected="40" show-values></loomi-slider>
---
import "@loomidev/slider";
---
<loomi-slider name="budget" min="0" max="100" step="5" selected="40" show-values></loomi-slider>

Frameworks such as Next.js, Nuxt, SvelteKit, and Astro sometimes render HTML on the server before browser-only code runs. If your framework complains, move the Loomi import to client-side code. In Next.js, that usually means a component with "use client"; in Nuxt, it often means a .client.ts plugin.

  • @loomidev/core