# Price slider with bubbles

> Two handles with little value bubbles, a highlighted stretch between them and the range shown above.

- Category: [Filters](https://library.aimran.es/components/filters)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-f-range-price
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

The price filter of an online furniture shop is the obvious home for it: drag the left handle to skip the cheapest pieces, the right one to stay on budget. A bubble shows the exact figure while you drag. If you searched for a dual range slider or a price filter in HTML and CSS, this is it.

Round the values to steps that make sense for your prices, like tens of euros, rather than showing 43 or 127. Set the maximum near your most expensive product, not at a random high number, or the useful part of the track gets squeezed.

## Code

### HTML

```html
<div class="uv-frp"><div class="hd"><span>Price</span><b class="out">40 € – 160 €</b></div><div class="tk"><span class="fill"></span><i class="h a" data-h="a"><em>40 €</em></i><i class="h b" data-h="b"><em>160 €</em></i></div></div>
```

### CSS

```css
.uv-frp {
  --c1: #0071e3;
  --c2: #8ec5ff;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uv-frp {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  width: 19em;
  display: flex;
  flex-direction: column;
  gap: 1.6em;
}

.uv-frp .hd {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: calc(var(--s) * .92);
}

.uv-frp .hd span {
  opacity: .6;
}

.uv-frp .hd b {
  color: var(--c1);
  font-weight: 700;
}

.uv-frp .tk {
  position: relative;
  height: 5px;
  border-radius: 999px;
  background: color-mix(in srgb,var(--fg) 12%,transparent);
}

.uv-frp .fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg,var(--c1),var(--c2));
}

.uv-frp .h {
  position: absolute;
  top: 50%;
  width: 1.5em;
  height: 1.5em;
  margin: -.75em 0 0 -.75em;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 2px 8px rgba(0,0,0,.22),inset 0 0 0 2px var(--c1);
  cursor: grab;
  touch-action: none;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-frp .h:hover,.uv-frp .h.drag {
  transform: scale(1.18);
}

.uv-frp .h.drag {
  cursor: grabbing;
}

.uv-frp .h em {
  position: absolute;
  bottom: 2em;
  left: 50%;
  translate: -50% 0;
  padding: .3em .6em;
  border-radius: .6em;
  font-size: calc(var(--s) * .72);
  font-weight: 700;
  font-style: normal;
  white-space: nowrap;
  color: #fff;
  background: var(--c1);
  opacity: 0;
  transform: translateY(.3em) scale(.9);
  transition: all calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-frp .h em::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  translate: -50% -1px;
  border: .35em solid transparent;
  border-top-color: var(--c1);
}

.uv-frp .h:hover em,.uv-frp .h.drag em {
  opacity: 1;
  transform: none;
}
```

### JavaScript

```js
document.querySelectorAll(".uv-frp").forEach(el => {
  const tk=el.querySelector(".tk"),f=el.querySelector(".fill"),out=el.querySelector(".out"),A=el.querySelector(".h.a"),Bh=el.querySelector(".h.b");let v={a:20,b:80};const draw=()=>{const lo=Math.min(v.a,v.b),hi=Math.max(v.a,v.b);f.style.left=lo+"%";f.style.width=(hi-lo)+"%";A.style.left=v.a+"%";Bh.style.left=v.b+"%";const p=x=>Math.round(x*4)+" €";A.querySelector("em").textContent=p(v.a);Bh.querySelector("em").textContent=p(v.b);out.textContent=p(lo)+" – "+p(hi)};[A,Bh].forEach(h=>{h.addEventListener("pointerdown",e=>{h.setPointerCapture(e.pointerId);h.classList.add("drag")});h.addEventListener("pointermove",e=>{if(!h.classList.contains("drag"))return;const r=tk.getBoundingClientRect();v[h.dataset.h]=Math.max(0,Math.min(100,(e.clientX-r.left)/r.width*100));draw()});h.addEventListener("pointerup",()=>h.classList.remove("drag"))});draw()
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uv-frp {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  width: 19em;
  display: flex;
  flex-direction: column;
  gap: 1.6em;
}

.uv-frp .hd {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: calc(var(--s) * .92);
}

.uv-frp .hd span {
  opacity: .6;
}

.uv-frp .hd b {
  color: var(--c1);
  font-weight: 700;
}

.uv-frp .tk {
  position: relative;
  height: 5px;
  border-radius: 999px;
  background: color-mix(in srgb,var(--fg) 12%,transparent);
}

.uv-frp .fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg,var(--c1),var(--c2));
}

.uv-frp .h {
  position: absolute;
  top: 50%;
  width: 1.5em;
  height: 1.5em;
  margin: -.75em 0 0 -.75em;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 2px 8px rgba(0,0,0,.22),inset 0 0 0 2px var(--c1);
  cursor: grab;
  touch-action: none;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-frp .h:hover,.uv-frp .h.drag {
  transform: scale(1.18);
}

.uv-frp .h.drag {
  cursor: grabbing;
}

.uv-frp .h em {
  position: absolute;
  bottom: 2em;
  left: 50%;
  translate: -50% 0;
  padding: .3em .6em;
  border-radius: .6em;
  font-size: calc(var(--s) * .72);
  font-weight: 700;
  font-style: normal;
  white-space: nowrap;
  color: #fff;
  background: var(--c1);
  opacity: 0;
  transform: translateY(.3em) scale(.9);
  transition: all calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-frp .h em::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  translate: -50% -1px;
  border: .35em solid transparent;
  border-top-color: var(--c1);
}

.uv-frp .h:hover em,.uv-frp .h.drag em {
  opacity: 1;
  transform: none;
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const tk=el.querySelector(".tk"),f=el.querySelector(".fill"),out=el.querySelector(".out"),A=el.querySelector(".h.a"),Bh=el.querySelector(".h.b");let v={a:20,b:80};const draw=()=>{const lo=Math.min(v.a,v.b),hi=Math.max(v.a,v.b);f.style.left=lo+"%";f.style.width=(hi-lo)+"%";A.style.left=v.a+"%";Bh.style.left=v.b+"%";const p=x=>Math.round(x*4)+" €";A.querySelector("em").textContent=p(v.a);Bh.querySelector("em").textContent=p(v.b);out.textContent=p(lo)+" – "+p(hi)};[A,Bh].forEach(h=>{h.addEventListener("pointerdown",e=>{h.setPointerCapture(e.pointerId);h.classList.add("drag")});h.addEventListener("pointermove",e=>{if(!h.classList.contains("drag"))return;const r=tk.getBoundingClientRect();v[h.dataset.h]=Math.max(0,Math.min(100,(e.clientX-r.left)/r.width*100));draw()});h.addEventListener("pointerup",()=>h.classList.remove("drag"))});draw()
}

export default function FRangePrice() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-frp"><div className="hd"><span>Price</span><b className="out">40 € – 160 €</b></div><div className="tk"><span className="fill"></span><i className="h a" data-h="a"><em>40 €</em></i><i className="h b" data-h="b"><em>160 €</em></i></div></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 slider with bubbles” block (Filters) from AIMRAN Library to my project.

## What it is
Two handles with little value bubbles, a highlighted stretch between them and the range shown above.

## Chosen settings
- Main color: #0071e3
- Secondary color: #8ec5ff
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)

## 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 plain HTML and CSS (the reference wraps it in a React component with its CSS). 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
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uv-frp {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  width: 19em;
  display: flex;
  flex-direction: column;
  gap: 1.6em;
}

.uv-frp .hd {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: calc(var(--s) * .92);
}

.uv-frp .hd span {
  opacity: .6;
}

.uv-frp .hd b {
  color: var(--c1);
  font-weight: 700;
}

.uv-frp .tk {
  position: relative;
  height: 5px;
  border-radius: 999px;
  background: color-mix(in srgb,var(--fg) 12%,transparent);
}

.uv-frp .fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg,var(--c1),var(--c2));
}

.uv-frp .h {
  position: absolute;
  top: 50%;
  width: 1.5em;
  height: 1.5em;
  margin: -.75em 0 0 -.75em;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 2px 8px rgba(0,0,0,.22),inset 0 0 0 2px var(--c1);
  cursor: grab;
  touch-action: none;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-frp .h:hover,.uv-frp .h.drag {
  transform: scale(1.18);
}

.uv-frp .h.drag {
  cursor: grabbing;
}

.uv-frp .h em {
  position: absolute;
  bottom: 2em;
  left: 50%;
  translate: -50% 0;
  padding: .3em .6em;
  border-radius: .6em;
  font-size: calc(var(--s) * .72);
  font-weight: 700;
  font-style: normal;
  white-space: nowrap;
  color: #fff;
  background: var(--c1);
  opacity: 0;
  transform: translateY(.3em) scale(.9);
  transition: all calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-frp .h em::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  translate: -50% -1px;
  border: .35em solid transparent;
  border-top-color: var(--c1);
}

.uv-frp .h:hover em,.uv-frp .h.drag em {
  opacity: 1;
  transform: none;
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const tk=el.querySelector(".tk"),f=el.querySelector(".fill"),out=el.querySelector(".out"),A=el.querySelector(".h.a"),Bh=el.querySelector(".h.b");let v={a:20,b:80};const draw=()=>{const lo=Math.min(v.a,v.b),hi=Math.max(v.a,v.b);f.style.left=lo+"%";f.style.width=(hi-lo)+"%";A.style.left=v.a+"%";Bh.style.left=v.b+"%";const p=x=>Math.round(x*4)+" €";A.querySelector("em").textContent=p(v.a);Bh.querySelector("em").textContent=p(v.b);out.textContent=p(lo)+" – "+p(hi)};[A,Bh].forEach(h=>{h.addEventListener("pointerdown",e=>{h.setPointerCapture(e.pointerId);h.classList.add("drag")});h.addEventListener("pointermove",e=>{if(!h.classList.contains("drag"))return;const r=tk.getBoundingClientRect();v[h.dataset.h]=Math.max(0,Math.min(100,(e.clientX-r.left)/r.width*100));draw()});h.addEventListener("pointerup",()=>h.classList.remove("drag"))});draw()
}

export default function FRangePrice() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-frp"><div className="hd"><span>Price</span><b className="out">40 € – 160 €</b></div><div className="tk"><span className="fill"></span><i className="h a" data-h="a"><em>40 €</em></i><i className="h b" data-h="b"><em>160 €</em></i></div></div>
      </div>
    </>
  );
}
```

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