# Clear filters button

> A button that only appears once a filter is active, shows how many are on and resets them in one click.

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

## Where to use it

On a stock photo site, people stack filters fast: Illustration, Vector, Photo, Video. When results dry up, they need a quick way out. This button stays hidden until there's something to clear, then slides in with a count. That way there's no dead button sitting on a page with no filters. Often searched as a reset filters button.

Put it near the filters themselves, not at the far end of the page. The number matters: “Clear filters (3)” tells people how much they're about to undo. Pair it with an empty state that suggests clearing when there are no results.

## Code

### HTML

```html
<div class="uv-fcr"><div class="rw"><button class="c">Design</button><button class="c">Code</button><button class="c">Photos</button><button class="c">Video</button></div><button class="cl"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg><b>Clear filters</b><i class="n">0</i></button></div>
```

### CSS

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

.uv-fcr {
  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;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
}

.uv-fcr .rw {
  display: flex;
  flex-wrap: wrap;
  gap: .45em;
  justify-content: center;
}

.uv-fcr .c {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 550;
  line-height: 1;
  padding: .72em 1.25em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  position: relative;
  transition: color calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.32s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  font-size: calc(var(--s) * .88);
  background: color-mix(in srgb,var(--fg) 7%,transparent);
}

.uv-fcr .c:hover {
  transform: translateY(-1px);
}

.uv-fcr .c.on {
  color: #fff;
  background: var(--c1);
  box-shadow: 0 7px 18px color-mix(in srgb,var(--c1) 32%,transparent);
}

.uv-fcr .cl {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 550;
  line-height: 1;
  padding: .72em 1.25em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  position: relative;
  transition: color calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.32s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  display: inline-flex;
  align-items: center;
  gap: .45em;
  font-size: calc(var(--s) * .85);
  color: var(--c1);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb,var(--c1) 32%,transparent);
  opacity: 0;
  transform: translateY(-.6em) scale(.9);
  pointer-events: none;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.42s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-fcr.has .cl {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.uv-fcr .cl:hover {
  background: color-mix(in srgb,var(--c1) 10%,transparent);
}

.uv-fcr .cl svg {
  width: .85em;
  height: .85em;
}

.uv-fcr .n {
  display: grid;
  place-items: center;
  min-width: 1.4em;
  padding: .15em .35em;
  border-radius: 999px;
  font-size: calc(var(--s) * .7);
  font-style: normal;
  font-weight: 700;
  color: #fff;
  background: var(--c1);
}
```

### JavaScript

```js
document.querySelectorAll(".uv-fcr").forEach(el => {
  const n=el.querySelector(".n");const upd=()=>{const k=el.querySelectorAll(".c.on").length;n.textContent=k;el.classList.toggle("has",k>0)};el.querySelectorAll(".c").forEach(c=>c.addEventListener("click",()=>{c.classList.toggle("on");upd()}));el.querySelector(".cl").addEventListener("click",()=>{el.querySelectorAll(".c").forEach(c=>c.classList.remove("on"));upd()});upd()
});
```

### 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-fcr {
  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;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
}

.uv-fcr .rw {
  display: flex;
  flex-wrap: wrap;
  gap: .45em;
  justify-content: center;
}

.uv-fcr .c {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 550;
  line-height: 1;
  padding: .72em 1.25em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  position: relative;
  transition: color calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.32s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  font-size: calc(var(--s) * .88);
  background: color-mix(in srgb,var(--fg) 7%,transparent);
}

.uv-fcr .c:hover {
  transform: translateY(-1px);
}

.uv-fcr .c.on {
  color: #fff;
  background: var(--c1);
  box-shadow: 0 7px 18px color-mix(in srgb,var(--c1) 32%,transparent);
}

.uv-fcr .cl {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 550;
  line-height: 1;
  padding: .72em 1.25em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  position: relative;
  transition: color calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.32s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  display: inline-flex;
  align-items: center;
  gap: .45em;
  font-size: calc(var(--s) * .85);
  color: var(--c1);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb,var(--c1) 32%,transparent);
  opacity: 0;
  transform: translateY(-.6em) scale(.9);
  pointer-events: none;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.42s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-fcr.has .cl {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.uv-fcr .cl:hover {
  background: color-mix(in srgb,var(--c1) 10%,transparent);
}

.uv-fcr .cl svg {
  width: .85em;
  height: .85em;
}

.uv-fcr .n {
  display: grid;
  place-items: center;
  min-width: 1.4em;
  padding: .15em .35em;
  border-radius: 999px;
  font-size: calc(var(--s) * .7);
  font-style: normal;
  font-weight: 700;
  color: #fff;
  background: var(--c1);
}
`;

// 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 n=el.querySelector(".n");const upd=()=>{const k=el.querySelectorAll(".c.on").length;n.textContent=k;el.classList.toggle("has",k>0)};el.querySelectorAll(".c").forEach(c=>c.addEventListener("click",()=>{c.classList.toggle("on");upd()}));el.querySelector(".cl").addEventListener("click",()=>{el.querySelectorAll(".c").forEach(c=>c.classList.remove("on"));upd()});upd()
}

export default function FDeskClear() {
  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-fcr"><div className="rw"><button className="c">Design</button><button className="c">Code</button><button className="c">Photos</button><button className="c">Video</button></div><button className="cl"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.6" strokeLinecap="round"><path d="M6 6l12 12M18 6L6 18" /></svg><b>Clear filters</b><i className="n">0</i></button></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 “Clear filters button” block (Filters) from AIMRAN Library to my project.

## What it is
A button that only appears once a filter is active, shows how many are on and resets them in one click.

## 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-fcr {
  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;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
}

.uv-fcr .rw {
  display: flex;
  flex-wrap: wrap;
  gap: .45em;
  justify-content: center;
}

.uv-fcr .c {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 550;
  line-height: 1;
  padding: .72em 1.25em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  position: relative;
  transition: color calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.32s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  font-size: calc(var(--s) * .88);
  background: color-mix(in srgb,var(--fg) 7%,transparent);
}

.uv-fcr .c:hover {
  transform: translateY(-1px);
}

.uv-fcr .c.on {
  color: #fff;
  background: var(--c1);
  box-shadow: 0 7px 18px color-mix(in srgb,var(--c1) 32%,transparent);
}

.uv-fcr .cl {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 550;
  line-height: 1;
  padding: .72em 1.25em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  position: relative;
  transition: color calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.32s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  display: inline-flex;
  align-items: center;
  gap: .45em;
  font-size: calc(var(--s) * .85);
  color: var(--c1);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb,var(--c1) 32%,transparent);
  opacity: 0;
  transform: translateY(-.6em) scale(.9);
  pointer-events: none;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.42s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-fcr.has .cl {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.uv-fcr .cl:hover {
  background: color-mix(in srgb,var(--c1) 10%,transparent);
}

.uv-fcr .cl svg {
  width: .85em;
  height: .85em;
}

.uv-fcr .n {
  display: grid;
  place-items: center;
  min-width: 1.4em;
  padding: .15em .35em;
  border-radius: 999px;
  font-size: calc(var(--s) * .7);
  font-style: normal;
  font-weight: 700;
  color: #fff;
  background: var(--c1);
}
`;

// 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 n=el.querySelector(".n");const upd=()=>{const k=el.querySelectorAll(".c.on").length;n.textContent=k;el.classList.toggle("has",k>0)};el.querySelectorAll(".c").forEach(c=>c.addEventListener("click",()=>{c.classList.toggle("on");upd()}));el.querySelector(".cl").addEventListener("click",()=>{el.querySelectorAll(".c").forEach(c=>c.classList.remove("on"));upd()});upd()
}

export default function FDeskClear() {
  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-fcr"><div className="rw"><button className="c">Design</button><button className="c">Code</button><button className="c">Photos</button><button className="c">Video</button></div><button className="cl"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.6" strokeLinecap="round"><path d="M6 6l12 12M18 6L6 18" /></svg><b>Clear filters</b><i className="n">0</i></button></div>
      </div>
    </>
  );
}
```

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