All effectsClick & switch

Click Ripple

点击涟漪

A circular highlight expands from the press point and fades inside the control.

Press the button at different spots

Where to use it

Give buttons or touch controls immediate feedback at the point of interaction. Place the highlight inside the pressed surface so nearby controls stay visually distinct, especially on touchscreens.

Practical example

On a mobile restaurant menu, tapping Add on a dish sends a pulse out from beneath your thumb. The pulse fades inside that button while the order total updates.

Also called

  • Tap Ripple

AI prompt

Add Click Ripple to [target control]. Start a fading circle at the local pointer coordinates and make it large enough to cover the control. Clip it to the same corner radius. Center the ripple for keyboard activation, retain the button’s existing action, and use a brief color feedback for reduced motion.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Click Ripple</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .ripple-button {
      position: relative;
      isolation: isolate;
      min-width: 132px;
      padding: 14px 19px;
      overflow: hidden;
      color: #271a37;
      background: #d5c5ff;
      border: 1px solid #eccffb;
      border-radius: 999px;
      box-shadow: 0 0 0 7px #b89af820, 0 0 0 15px #b89af811;
      font: inherit;
      font-size: 13px;
      font-weight: 750;
      cursor: pointer;
    }
    .ripple-button:active { background: #eee3ff; }
    .ripple-label { position: relative; z-index: 1; }
    .ripple-wave {
      position: absolute;
      width: var(--diameter);
      height: var(--diameter);
      left: var(--origin-x);
      top: var(--origin-y);
      border-radius: 50%;
      background: #fff;
      animation: expand-ripple 520ms ease-out forwards;
      pointer-events: none;
    }
    @keyframes expand-ripple {
      from { transform: translate(-50%, -50%) scale(0); opacity: 0.8; }
      to { transform: translate(-50%, -50%) scale(1); opacity: 0; }
    }
    @media (prefers-reduced-motion: reduce) {
      .ripple-wave { animation: none; display: none; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <button class="ripple-button" type="button">
      <span class="ripple-label">Tap here</span>
    </button>
  </main>
  <script>
    const button = document.querySelector(".ripple-button");
    const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)");

    button.addEventListener("click", (event) => {
      button.querySelector(".ripple-wave")?.remove();
      if (reduceMotion.matches) return;

      const { left, top, width, height } = button.getBoundingClientRect();
      const x = event.detail === 0 ? width / 2 : event.clientX - left;
      const y = event.detail === 0 ? height / 2 : event.clientY - top;
      const maxX = Math.max(x, width - x);
      const maxY = Math.max(y, height - y);
      const wave = document.createElement("span");

      wave.className = "ripple-wave";
      wave.setAttribute("aria-hidden", "true");
      wave.style.setProperty("--origin-x", x + "px");
      wave.style.setProperty("--origin-y", y + "px");
      wave.style.setProperty("--diameter", (2 * Math.hypot(maxX, maxY)) + "px");
      wave.addEventListener("animationend", () => wave.remove(), { once: true });
      button.append(wave);
    });
  </script>
</body>
</html>

Original example by UI Skills