# Ripple click button

> A soft wave spreads out from the exact spot where you click or tap the button.

- Category: [Buttons](https://library.aimran.es/components/buttons)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-btn-ripple
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

The ripple effect gives instant feedback on press, which matters in web apps people use with their thumbs: “Add to cart” in a food delivery app, “Save” in a notes tool or the filters of a booking dashboard. If you know Material Design, the click ripple on a button will feel familiar. It uses a few lines of JavaScript.

Unlike hover effects, this one works just as well on phones, since it reacts to the tap itself. Very light button colors make the white wave hard to see, so give it a mid or dark tone. Keep the speed low for a calmer, more premium feel.

## Code

### HTML

```html
<button class="uv-ripple">Click me</button>
```

### CSS

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

.uv-ripple {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 600;
  line-height: 1;
  padding: 1em 2em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
  color: #fff;
  background: var(--c1);
}

.uv-ripple i {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px;
  border-radius: 50%;
  background: rgba(255,255,255,.55);
  pointer-events: none;
  animation: uv-rip calc(0.7s / var(--k)) cubic-bezier(.25,.1,.25,1) forwards;
}

@keyframes uv-rip {
  to {
    transform: scale(40);
    opacity: 0;
  }
}
```

### JavaScript

```js
document.querySelectorAll(".uv-ripple").forEach(el => {
  el.addEventListener("pointerdown",e=>{const r=el.getBoundingClientRect(),i=document.createElement("i");i.style.left=e.clientX-r.left+"px";i.style.top=e.clientY-r.top+"px";el.appendChild(i);setTimeout(()=>i.remove(),900)})
});
```

### 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-ripple {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 600;
  line-height: 1;
  padding: 1em 2em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
  color: #fff;
  background: var(--c1);
}

.uv-ripple i {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px;
  border-radius: 50%;
  background: rgba(255,255,255,.55);
  pointer-events: none;
  animation: uv-rip calc(0.7s / var(--k)) cubic-bezier(.25,.1,.25,1) forwards;
}

@keyframes uv-rip {
  to {
    transform: scale(40);
    opacity: 0;
  }
}
`;

// 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) {
  el.addEventListener("pointerdown",e=>{const r=el.getBoundingClientRect(),i=document.createElement("i");i.style.left=e.clientX-r.left+"px";i.style.top=e.clientY-r.top+"px";el.appendChild(i);setTimeout(()=>i.remove(),900)})
}

export default function BtnRipple() {
  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}
      >
        <button className="uv-ripple">Click me</button>
      </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 “Ripple click button” block (Buttons) from AIMRAN Library to my project.

## What it is
A soft wave spreads out from the exact spot where you click or tap the button.

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

## 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-ripple {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 600;
  line-height: 1;
  padding: 1em 2em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
  color: #fff;
  background: var(--c1);
}

.uv-ripple i {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px;
  border-radius: 50%;
  background: rgba(255,255,255,.55);
  pointer-events: none;
  animation: uv-rip calc(0.7s / var(--k)) cubic-bezier(.25,.1,.25,1) forwards;
}

@keyframes uv-rip {
  to {
    transform: scale(40);
    opacity: 0;
  }
}
`;

// 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) {
  el.addEventListener("pointerdown",e=>{const r=el.getBoundingClientRect(),i=document.createElement("i");i.style.left=e.clientX-r.left+"px";i.style.top=e.clientY-r.top+"px";el.appendChild(i);setTimeout(()=>i.remove(),900)})
}

export default function BtnRipple() {
  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}
      >
        <button className="uv-ripple">Click me</button>
      </div>
    </>
  );
}
```

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