Slider
A draggable input for picking a value or range — volume, price filters, settings — with the neobrutalist borders-and-shadows treatment.
import { Slider } from "@/components/ui/slider"
export function SliderDemo() {The slider lets users pick a value — or a range between two thumbs — by dragging along a track. Built on the Base UI Slider component and styled to the neobrutalist recipe: thick borders, a hard-shadowed square thumb, and a solid filled range.
Reach for it when:
- Volume, brightness, playback position — media players and device-style controls where dragging beats typing.
- Price and range filters — two thumbs give you a min–max filter for search and e-commerce listings.
- Numeric settings with sane bounds — opacity, border radius, font size; anywhere a bounded number is better shown than typed.
Installation#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/slider.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/slider.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/slider.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/slider.json
Install the following dependencies:
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/react
Copy and paste the following code into your project.
"use client"
import * as React from "react"
import { Slider as SliderPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
function Slider({
className,
defaultValue,
value,
min = 0,
max = 100,
// Pulled out of the root spread so they land on the Thumb (the element
// with role="slider" that screen readers announce), not just the Root.
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledby,
...props
}: React.ComponentProps<typeof SliderPrimitive.Root>) {
const _values = React.useMemo(
() =>
Array.isArray(value)
? value
: Array.isArray(defaultValue)
? defaultValue
: [min, max],
[value, defaultValue, min, max]
)
return (
<SliderPrimitive.Root
data-slot="slider"
defaultValue={defaultValue}
value={value}
min={min}
max={max}
className={cn(
"relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-vertical:h-full data-vertical:min-h-40 data-vertical:w-auto data-vertical:flex-col",
className
)}
{...props}
>
<SliderPrimitive.Track
data-slot="slider-track"
className="relative grow overflow-hidden border-2 bg-background data-horizontal:h-3 data-horizontal:w-full data-vertical:h-full data-vertical:w-3"
>
<SliderPrimitive.Range
data-slot="slider-range"
className="absolute bg-primary select-none data-horizontal:h-full data-vertical:w-full"
/>
</SliderPrimitive.Track>
{Array.from({ length: _values.length }, (_, index) => (
<SliderPrimitive.Thumb
data-slot="slider-thumb"
key={index}
aria-label={ariaLabel}
aria-labelledby={ariaLabelledby}
className="relative block size-4.5 shrink-0 border-2 bg-background shadow-sm transition-[color,box-shadow] select-none after:absolute after:-inset-2 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:pointer-events-none disabled:opacity-50"
/>
))}
</SliderPrimitive.Root>
)
}
export { Slider }
Update the import paths to match your project setup.
Usage#
import { Slider } from "@/components/ui/slider"<Slider defaultValue={[33]} max={100} step={1} />Examples#
Range#
Use an array with two values for a range slider.
import { Slider } from "@/components/ui/slider"
export function SliderRange() {Multiple Thumbs#
Use an array with multiple values for multiple thumbs.
import { Slider } from "@/components/ui/slider"
export function SliderMultiple() {Vertical#
Use orientation="vertical" for a vertical slider.
import { Slider } from "@/components/ui/slider"
export function SliderVertical() {Controlled#
"use client"
import * as React from "react"Disabled#
Use the disabled prop to disable the slider.
import { Slider } from "@/components/ui/slider"
export function SliderDisabled() {RTL#
To enable RTL support in Neobrutalism.com, see the RTL configuration guide.
"use client"
import * as React from "react"Accessibility#
The slider follows the WAI-ARIA Slider pattern: each thumb is a focusable role="slider" element with aria-valuemin, aria-valuemax, and aria-valuenow kept in sync, backed by a hidden input for form submission. A slider has no visible label of its own, so pass aria-label or aria-labelledby — this wrapper forwards both to the thumb, the element screen readers actually announce.
Keyboard interactions:
| Key | Action |
|---|---|
Tab / Shift + Tab | Move focus between thumbs and out |
ArrowRight / ArrowUp | Increase the value by one step |
ArrowLeft / ArrowDown | Decrease the value by one step |
PageUp / PageDown | Increase / decrease by largeStep (default 10) |
Shift + Arrow | Increase / decrease by largeStep |
Home / End | Jump to the minimum / maximum |
In RTL, the horizontal arrow keys follow the reading direction.
API Reference#
See the Base UI Slider documentation.