UI Patterns
Feedback

Haptics

Vibration feedback on the web — what the Vibration API can do, where it doesn't exist (all of iOS), and how to use it without annoying people.

Haptics are the third feedback channel next to animation and sound — and the only one that works when the user isn't looking and the phone is muted. On the web it's also the least available one.

Support

The Vibration API is a single call, navigator.vibrate(pattern). Where it works (MDN compatibility data):

BrowserStatus
Chrome, Edge, Samsung Internet, Opera on AndroidWorks. Requires a user gesture (since Chrome 60) and doesn't work in cross-origin iframes.
Firefox for AndroidThe method exists and returns true, but vibration is disabled — feature detection lies.
Firefox desktopRemoved in Firefox 129.
Safari (macOS and iOS), every iOS browserNever supported.

So haptics on the web are an Android-only progressive enhancement. Design so that nothing is lost without them — Apple's guidance for its own platforms applies doubly here: "Make haptics optional … make sure people can still enjoy your app or game without them."

iOS workaround, not recommended. Safari 17.4 added <input type="checkbox" switch>, which plays a system haptic when toggled. Libraries such as ios-haptics overlay a transparent <label> wired to a hidden switch so a real tap on any element toggles it. It depends on undocumented behaviour, and Apple has already narrowed it: since iOS 26.5 toggling the switch from script plays nothing, only a direct tap does. So it can't buzz on a result, a timer or mid-gesture, and it's not used here.

Patterns

Buttons below call navigator.vibrate with each pattern (alternating vibrate / pause, in ms). The timeline under each one shows the pattern, so the demo still makes sense where nothing vibrates.

Checking support…

Install with the shadcn CLI, or copy the source below.

npx shadcn@latest add https://ui-patterns.stereobooster.com/r/feedback-haptics.json
lib/feedback-haptics.ts
export type FeedbackHaptic = "tap" | "tick" | "success" | "warning" | "error";

/**
 * Vibration patterns in ms, alternating vibrate / pause. Starting points,
 * not research values — phone motors differ a lot, so tune on devices.
 */
export const HAPTIC_PATTERNS: Record<FeedbackHaptic, number[]> = {
  tick: [8],
  tap: [15],
  success: [15, 80, 25],
  warning: [30, 120, 30],
  error: [40, 60, 40, 60, 40],
};

export function canVibrate() {
  return typeof navigator !== "undefined" && "vibrate" in navigator;
}

/**
 * Must be called from a user gesture (Chrome ignores it otherwise).
 * Returns whether the browser accepted the request — Firefox for Android
 * returns `true` without vibrating, so `true` is not proof of a buzz.
 */
export function playFeedbackHaptic(haptic: FeedbackHaptic) {
  if (!canVibrate()) return false;
  return navigator.vibrate(HAPTIC_PATTERNS[haptic]);
}

The pattern values are starting points, not research results: phone vibration motors range from crisp linear actuators to slow rotating motors, and a 10 ms pulse that feels like a tick on one phone is imperceptible on another. Tune on real devices.

In context

A quantity stepper: a light tick on every step, a stronger buzz — plus a shake and a message — at the limit.

Checking support…

Quantity
1

Quantity 1

Preference

Same model as sounds: off until the user turns it on, persisted, synced across tabs. play returns early while disabled, so call sites don't need to check.

Install with the shadcn CLI (it also installs lib/feedback-haptics.ts), or copy the source below.

npx shadcn@latest add https://ui-patterns.stereobooster.com/r/use-feedback-haptics.json
hooks/use-feedback-haptics.ts
"use client";

import * as React from "react";

import {
  canVibrate,
  playFeedbackHaptic,
  type FeedbackHaptic,
} from "@/lib/feedback-haptics";

const STORAGE_KEY = "feedback-haptics-enabled";
const listeners = new Set<() => void>();

function readEnabled() {
  try {
    return localStorage.getItem(STORAGE_KEY) === "1";
  } catch {
    return false;
  }
}

let enabled: boolean | null = null;

function getEnabled() {
  enabled ??= readEnabled();
  return enabled;
}

function setEnabled(value: boolean) {
  enabled = value;
  try {
    localStorage.setItem(STORAGE_KEY, value ? "1" : "0");
  } catch {}
  listeners.forEach((listener) => listener());
}

function subscribe(listener: () => void) {
  listeners.add(listener);
  const onStorage = (event: StorageEvent) => {
    if (event.key !== STORAGE_KEY) return;
    enabled = readEnabled();
    listener();
  };
  window.addEventListener("storage", onStorage);
  return () => {
    listeners.delete(listener);
    window.removeEventListener("storage", onStorage);
  };
}

const subscribeNever = () => () => {};

/**
 * Haptics are off until the user turns them on; the choice is persisted and
 * synced across tabs. `supported` is `null` during server rendering.
 */
export function useFeedbackHaptics() {
  const isEnabled = React.useSyncExternalStore(
    subscribe,
    getEnabled,
    () => false,
  );
  const supported = React.useSyncExternalStore(
    subscribeNever,
    canVibrate,
    () => null,
  );

  const play = React.useCallback((haptic: FeedbackHaptic) => {
    if (!getEnabled()) return false;
    return playFeedbackHaptic(haptic);
  }, []);

  return { enabled: isEnabled, setEnabled, supported, play };
}

What research says

  • Tactile feedback makes touchscreen typing measurably better. Hoggan, Brewster & Johnston (2008) compared a physical keyboard, a plain touchscreen and a touchscreen with tactile feedback, sitting and on the move: adding tactile feedback "significantly improved finger-based text entry, bringing it close to the performance of a real physical keyboard", and better actuators improved it further. This is the strongest evidence for haptics in any feedback channel covered in this section.
  • Vibration has the tightest timing budget. Kaaresoja (2016) found tactile feedback should arrive 5–50 ms after touch to feel simultaneous — versus 30–85 ms for visual and 20–70 ms for audio. With vibration present, the visual response can arrive later (about 100 ms) and the pair still feels simultaneous. Call navigator.vibrate first in the handler, before any state updates or rendering.
  • Affect depends on design, not context. Seebode, Schleicher & Wechsung (2013) found the emotional impression of vibration patterns stayed the same across usage contexts, and concluded that tactile messages are unobtrusive but "have to be designed carefully" — the pattern itself carries the meaning.

Rules

From Apple's Playing haptics guidelines, which hold for any platform:

  • Use haptics consistently — "build a clear, causal relationship between each haptic and the action that causes it." The same pattern for every success, a different one for every failure, never swapped.
  • Complement other feedback — "match the intensity and sharpness of a haptic with the intensity and sharpness of the animation it accompanies." The stepper pairs a light tick with a small number change, and a heavier buzz with a shake.
  • Avoid overusing haptics — "the best haptic experience is one that people may not be conscious of, but miss when it's turned off." No vibration on scroll, hover or typing in ordinary inputs.
  • Prefer short haptics for discrete events — long patterns dilute meaning. Everything above is under 250 ms.
  • Make haptics optional — the switch above.

Web-specific:

  • Only inside a user gesture. Chrome ignores vibrate otherwise, so you can't buzz when a network request completes later — vibrate on the tap, and use visual or sound feedback for the async result.
  • Don't trust the return value. Firefox for Android returns true without vibrating; there is no way to confirm a vibration happened.
  • navigator.vibrate(0) stops a pattern that is still running.

On this page