# Price range slider

> Two sliders for a minimum and maximum price, with a small histogram above showing where prices cluster.

- Category: [Inputs](https://library.aimran.es/components/inputs)
- Built with: React + Motion
- Live editor: https://library.aimran.es/blocks/price-range
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

A price filter with a histogram tells shoppers where most products sit before they drag anything. It is what you see on holiday rental sites, used car listings and bigger online shops. The two sliders never cross, and the prices update as you move them. If your catalog has a filter sidebar, this price range slider slots right into it.

The bars in the demo are sample data, so feed them your real price spread or they will mislead people. Adjust the histogram height to fit your sidebar, and change the currency sign if you do not sell in euros.

## Code

### React (Motion)

```tsx
import { useState } from "react";
import { motion } from "framer-motion";

const spring = { type: "spring" as const, stiffness: 300, damping: 30 };

const bars = [5, 8, 13, 20, 28, 35, 42, 50, 46, 38, 31, 23, 16, 10];

const rangeClass = [
  "h-1 w-full appearance-none rounded-full bg-black/5 outline-none dark:bg-white/10",
  "[&::-webkit-slider-thumb]:h-[22px] [&::-webkit-slider-thumb]:w-[22px] [&::-webkit-slider-thumb]:cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-white [&::-webkit-slider-thumb]:shadow-[0_1px_4px_rgba(0,0,0,0.25),0_0_0_0.5px_rgba(0,0,0,0.06)]",
  "[&::-moz-range-thumb]:h-[22px] [&::-moz-range-thumb]:w-[22px] [&::-moz-range-thumb]:cursor-pointer [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-none [&::-moz-range-thumb]:bg-white [&::-moz-range-thumb]:shadow-[0_1px_4px_rgba(0,0,0,0.25)]",
].join(" ");

interface PriceRangeProps {
  value?: [number, number];
  defaultValue?: [number, number];
  onChange?: (value: [number, number]) => void;
  height?: number;
}

export default function PriceRange({
  value,
  defaultValue = [150, 750],
  onChange,
  height = 1,
}: PriceRangeProps) {
  const [internal, setInternal] = useState<[number, number]>(defaultValue);
  const [a, b] = value ?? internal;

  const set = (next: [number, number]) => {
    if (value === undefined) setInternal(next);
    onChange?.(next);
  };

  return (
    <div className="w-72 rounded-[22px] bg-white p-5 text-[#1d1d1f] shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)] dark:bg-[#1c1c1e] dark:text-[#f5f5f7]">
      <div className="mb-3 flex h-16 items-end gap-1">
        {bars.map((h, i) => (
          <motion.i
            key={i}
            className="flex-1 rounded-t bg-[#0071e3]/30"
            animate={{ height: h * height }}
            transition={{ ...spring, delay: i * 0.02 }}
          />
        ))}
      </div>
      <div className="space-y-2">
        <input
          aria-label="Min price"
          className={rangeClass}
          type="range"
          min="0"
          max="1000"
          value={a}
          onChange={(e) => set([Math.min(Number(e.target.value), b - 25), b])}
        />
        <input
          aria-label="Max price"
          className={rangeClass}
          type="range"
          min="0"
          max="1000"
          value={b}
          onChange={(e) => set([a, Math.max(Number(e.target.value), a + 25)])}
        />
      </div>
      <div className="mt-3 flex justify-between text-sm">
        <span>{a} €</span>
        <span>{b} €</span>
      </div>
    </div>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Price range slider” block (Inputs) from AIMRAN Library to my project.

## What it is
Two sliders for a minimum and maximum price, with a small histogram above showing where prices cluster.

## Chosen settings
- Minimum: 150€ (from 0 to 450€)
- Maximum: 750€ (from 500 to 1000€)
- Histogram height: 1 (from 0.6 to 1.3)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with React + TypeScript, with framer-motion for the animation and lucide-react for the icons. If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
import { useState } from "react";
import { motion } from "framer-motion";

const spring = { type: "spring" as const, stiffness: 300, damping: 30 };

const bars = [5, 8, 13, 20, 28, 35, 42, 50, 46, 38, 31, 23, 16, 10];

const rangeClass = [
  "h-1 w-full appearance-none rounded-full bg-black/5 outline-none dark:bg-white/10",
  "[&::-webkit-slider-thumb]:h-[22px] [&::-webkit-slider-thumb]:w-[22px] [&::-webkit-slider-thumb]:cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-white [&::-webkit-slider-thumb]:shadow-[0_1px_4px_rgba(0,0,0,0.25),0_0_0_0.5px_rgba(0,0,0,0.06)]",
  "[&::-moz-range-thumb]:h-[22px] [&::-moz-range-thumb]:w-[22px] [&::-moz-range-thumb]:cursor-pointer [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-none [&::-moz-range-thumb]:bg-white [&::-moz-range-thumb]:shadow-[0_1px_4px_rgba(0,0,0,0.25)]",
].join(" ");

interface PriceRangeProps {
  value?: [number, number];
  defaultValue?: [number, number];
  onChange?: (value: [number, number]) => void;
  height?: number;
}

export default function PriceRange({
  value,
  defaultValue = [150, 750],
  onChange,
  height = 1,
}: PriceRangeProps) {
  const [internal, setInternal] = useState<[number, number]>(defaultValue);
  const [a, b] = value ?? internal;

  const set = (next: [number, number]) => {
    if (value === undefined) setInternal(next);
    onChange?.(next);
  };

  return (
    <div className="w-72 rounded-[22px] bg-white p-5 text-[#1d1d1f] shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)] dark:bg-[#1c1c1e] dark:text-[#f5f5f7]">
      <div className="mb-3 flex h-16 items-end gap-1">
        {bars.map((h, i) => (
          <motion.i
            key={i}
            className="flex-1 rounded-t bg-[#0071e3]/30"
            animate={{ height: h * height }}
            transition={{ ...spring, delay: i * 0.02 }}
          />
        ))}
      </div>
      <div className="space-y-2">
        <input
          aria-label="Min price"
          className={rangeClass}
          type="range"
          min="0"
          max="1000"
          value={a}
          onChange={(e) => set([Math.min(Number(e.target.value), b - 25), b])}
        />
        <input
          aria-label="Max price"
          className={rangeClass}
          type="range"
          min="0"
          max="1000"
          value={b}
          onChange={(e) => set([a, Math.max(Number(e.target.value), a + 25)])}
        />
      </div>
      <div className="mt-3 flex justify-between text-sm">
        <span>{a} €</span>
        <span>{b} €</span>
      </div>
    </div>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
