JavaScript Navigator vibrate() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

navigator.vibrate(pattern) pulses the device’s vibration hardware if it exists (MDN). Pass a number of milliseconds or an array that alternates vibrate and pause. A new call replaces any pattern already running.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call navigator.vibrate. Start with this line.

JavaScript
navigator.vibrate(pattern)
CallWhat it does
navigator.vibrate(pattern)Primary signature.
navigator.vibrate(...)Call with the arguments your case needs.

Built into the browser. Call vibrate(...) on a Navigator — no import required.

Library declarations
JavaScript
navigator.vibrate(pattern)

Parameters

ParameterDescription
patternRequired. Number of ms, or array of vibrate/pause ms

Return Value

Return ValueDescription
*boolean — accepted vs invalid params

JavaScript Examples

Example 1 — Short Pulse (MDN)

Vibrate once for 200 milliseconds from a button click.

JavaScript
document.querySelector("button").addEventListener("click", () => {
  if (typeof navigator.vibrate !== "function") {
    console.log("Vibration API not supported");
    return;
  }
  const ok = navigator.vibrate(200);
  console.log(ok ? "vibrate(200) accepted" : "vibrate(200) rejected");
});
Try It Yourself

How It Works

  1. Feature-detect so missing APIs fail quietly.
  2. Wire a click — sticky user activation is required (MDN).
  3. Pass one number — vibrate that many milliseconds once.
  4. Check the boolean — true means params were valid, not that you felt a buzz.

Example 2 — SOS Morse Pattern (MDN)

Alternate vibrate and pause values to spell SOS in Morse.

JavaScript
const SOS = [
  100, 30, 100, 30, 100, 30,
  200, 30, 200, 30, 200, 30,
  100, 30, 100, 30, 100
];

document.querySelector("button").addEventListener("click", () => {
  if (typeof navigator.vibrate !== "function") {
    console.log("unsupported");
    return;
  }
  const ok = navigator.vibrate(SOS);
  console.log(ok ? "SOS pattern started" : "SOS pattern rejected");
});
Try It Yourself

How It Works

  1. Array = rhythm — odd slots vibrate, even slots pause (0-based: on, off, on…).
  2. Short / long — 100 ms dots and 200 ms dashes with 30 ms gaps (MDN).
  3. One call runs the whole sequence; a new call replaces it.
  4. Keep it purposeful — long loops annoy users and may be truncated.

Example 3 — Cancel with vibrate(0)

Start a longer pattern, then stop it from a second button.

JavaScript
const start = document.getElementById("start");
const stop = document.getElementById("stop");

start.addEventListener("click", () => {
  if (!navigator.vibrate) return;
  navigator.vibrate([400, 200, 400, 200, 400, 200, 400]);
  console.log("long pattern started");
});

stop.addEventListener("click", () => {
  if (!navigator.vibrate) return;
  navigator.vibrate(0);
  console.log("canceled");
});
Try It Yourself

How It Works

  1. Start a pattern that lasts long enough to cancel mid-way.
  2. Call vibrate(0) — also works with [] or [0] (MDN).
  3. Same API starts and stops — no separate cancel method.
  4. Both need a gesture in supporting browsers (sticky activation).

Browser Support

navigator.vibrate() is part of the Vibration API and is not Baseline. Strong on Chromium mobile; absent in Safari; removed from Firefox desktop (129+). Always feature-detect and treat haptics as optional.

✓ Limited availability · Not Baseline

Navigator.vibrate()

Pulse vibration hardware with a ms value or pattern array — returns boolean.

Limited Not Baseline
Google Chrome Yes (Chrome 32+; best on Android)
Yes
Microsoft Edge Yes (Chromium Edge 79+)
Yes
Apple Safari No — never shipped
No
Opera Yes (Chromium-based)
Yes
Mozilla Firefox Removed desktop 129+; Android often no feel
No
Internet Explorer No Vibration API
No
vibrate() Limited

Bottom line: Detect vibrate, call only from a user gesture, keep patterns short, cancel with 0. See the MDN vibrate() reference.

Frequently Asked Questions

It pulses the device’s vibration hardware using a pattern of on/off intervals in milliseconds. If the device has no vibrator, the call has no physical effect (MDN).
No. MDN does not mark it Deprecated, Experimental, or Non-standard. It is Limited availability (not Baseline). Always feature-detect.
Sticky user activation is required. Call vibrate from a button click or similar UI interaction — not from page load or a timer alone (MDN).
true means the call was accepted (parameters valid). false means invalid parameters. true does not guarantee you will feel vibration (Silent/DND mode, desktop, or no hardware).
Call navigator.vibrate(0), navigator.vibrate([]), or navigator.vibrate([0]). A new pattern also replaces any pattern already running (MDN).
A number vibrates once for that many ms. An array alternates vibrate and pause: [vibrate, pause, vibrate, …]. MDN’s SOS Morse example uses a longer array.

Next: activeVRDisplays

Continue with Navigator properties in the tutorial series.

activeVRDisplays →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

21 people found this page helpful