JavaScript Navigator vibrate() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
User activation
Limited availability

What You’ll Learn

navigator.vibrate() pulses phone (and some tablet) vibration hardware. Learn single-duration vs pattern arrays, how to cancel, user-activation rules, five examples, and try-it labs best tested on a real mobile device.

01

Kind

Method

02

Returns

boolean

03

Status

Limited (not Baseline)

04

Needs

User activation

05

Pattern

ms or array

06

Cancel

vibrate(0)

Introduction

Games, chat apps, and form errors often give a short haptic pulse so the user feels feedback without staring at the screen. The Vibration API exposes that through navigator.vibrate().

Pass one number (vibrate that many milliseconds) or an array that alternates vibrate and pause. A new call replaces any pattern already running. Call it from a user gesture (button click). Silent / Do Not Disturb modes may block physical vibration even when the method returns true.

💡
No Dep / Exp / Non-standard banner

MDN marks Limited availability and sticky user activation, but not Deprecated, Experimental, or Non-standard. Always feature-detect and prefer short, purposeful patterns.

Understanding the vibrate() Method

  • One argument — a number of milliseconds, or an array of ms values.
  • Array meaning[vibrate, pause, vibrate, pause, …].
  • Replace previous — a new call stops the old pattern and starts the new one.
  • Cancel0, [], or [0] stops vibration.
  • Return valuetrue if parameters are valid; false if invalid.
  • No hardware — desktop / missing vibrator: usually no effect (still may return true).

📝 Syntax

General form of the method:

JavaScript
navigator.vibrate(pattern)

Parameters

  • pattern — a single number (ms) or an array of numbers alternating vibrate / pause.

Return value

  • true if the vibration was successfully started (or canceled with a valid cancel pattern).
  • false if the parameters are invalid.

MDN-style examples

JavaScript
navigator.vibrate(200); // vibrate for 200ms

navigator.vibrate([
  100, 30, 100, 30, 100, 30, 200, 30, 200, 30, 200, 30, 100, 30, 100, 30, 100
]); // Vibrate "SOS" in Morse

⚡ Quick Reference

GoalCode
Feature detecttypeof navigator.vibrate === "function"
Short buzznavigator.vibrate(200)
Patternnavigator.vibrate([100, 50, 100])
Cancelnavigator.vibrate(0)
Check resultconst ok = navigator.vibrate(100)
Call fromButton click / tap (user activation)

🔍 At a Glance

Four facts to remember about navigator.vibrate().

Returns
boolean

Valid pattern?

Status
Limited

Not Baseline

Needs
gesture

Sticky activation

Cancel
0 / []

Stops pattern

📋 Number vs Array Pattern

Single numberArray pattern
Examplevibrate(200)vibrate([100, 50, 100])
MeaningOne continuous buzzBuzz, pause, buzz, …
Best forSimple confirmationAlerts, Morse, game hits
Cancelvibrate(0)Same cancel forms

Examples Gallery

Vibration is easiest to feel on a phone. Desktop browsers may return true with no haptic effect. Always call from a button click so user activation is present.

📚 Getting Started

Detect support and fire a short buzz from a click.

Example 1 — Feature Detection

Check whether the Vibration API method exists.

JavaScript
const lines = [
  "vibrate: " +
    (typeof navigator.vibrate === "function" ? "available" : "missing"),
  "tip: test on a phone after a button click"
];
console.log(lines.join("\n"));
Try It Yourself

How It Works

If the method is missing, skip haptic UI — do not treat it as an error.

Example 2 — Vibrate 200ms (MDN)

Simplest pattern: one short pulse from a button click.

JavaScript
function buzzShort() {
  if (typeof navigator.vibrate !== "function") {
    return "API not supported";
  }
  const ok = navigator.vibrate(200);
  return ok ? "vibrate(200) accepted" : "vibrate(200) rejected";
}

// Call buzzShort() from a button click handler
Try It Yourself

How It Works

true means the browser accepted the pattern — not that you will always feel it.

📈 Practical Patterns

SOS Morse, cancel, and a safe helper for apps.

Example 3 — SOS Morse Pattern (MDN)

Array of vibrate / pause intervals that spells SOS in Morse timing.

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

function buzzSos() {
  if (typeof navigator.vibrate !== "function") {
    return "API not supported";
  }
  const ok = navigator.vibrate(SOS);
  return ok ? "SOS pattern started" : "SOS pattern rejected";
}

// Call buzzSos() from a button click
Try It Yourself

How It Works

Odd indices (0-based even) vibrate; odd positions pause — keep patterns short for UX.

Example 4 — Cancel an Ongoing Pattern

Start a long pattern, then stop it with vibrate(0).

JavaScript
function startLongBuzz() {
  if (typeof navigator.vibrate !== "function") {
    return "missing";
  }
  // Long alternating pattern — cancel with vibrate(0)
  navigator.vibrate([400, 200, 400, 200, 400, 200, 400]);
  return "long pattern started — call stopBuzz() to cancel";
}

function stopBuzz() {
  if (typeof navigator.vibrate !== "function") {
    return "missing";
  }
  const ok = navigator.vibrate(0);
  return ok ? "canceled with vibrate(0)" : "cancel rejected";
}

// Wire startLongBuzz / stopBuzz to two buttons
Try It Yourself

How It Works

[] and [0] also cancel. Starting a new pattern replaces the old one too.

Example 5 — Safe Vibrate Helper

One helper for apps: detect, call, and return a clear status.

JavaScript
function vibrateSafe(pattern) {
  if (typeof navigator.vibrate !== "function") {
    return { ok: false, reason: "missing-api" };
  }
  try {
    const accepted = navigator.vibrate(pattern);
    return {
      ok: accepted,
      reason: accepted ? "accepted" : "invalid-pattern"
    };
  } catch (err) {
    return { ok: false, reason: err.name };
  }
}

// From a button:
// console.log(JSON.stringify(vibrateSafe(150)));
// console.log(JSON.stringify(vibrateSafe([80, 40, 80])));
// console.log(JSON.stringify(vibrateSafe(0))); // cancel
Try It Yourself

How It Works

Keep haptics optional: success UX should never depend on feeling the buzz.

🚀 Common Use Cases

  • Form validation — short buzz when an error appears.
  • Chat / notifications — gentle pulse when a message arrives (with permission UX).
  • Games — hit / miss patterns with short arrays.
  • Timers — alert when a countdown finishes (from a user-started timer UI).
  • Accessibility care — keep patterns short; offer a setting to disable haptics.

🧠 How navigator.vibrate() Works

1

User taps a control

Sticky user activation unlocks the Vibration API.

Gesture
2

Pass a pattern

Number or array of millisecond intervals.

Pattern
3

Hardware pulses

If present and not blocked by Silent/DND.

Haptic
4

Boolean result

true if the pattern was accepted; false if invalid.

📝 Notes

  • Limited availability (not Baseline) — feature-detect always.
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Requires sticky user activation (call from a click / tap).
  • Silent / DND modes may block physical vibration.
  • Related: share(), unregisterProtocolHandler(), canShare(), Window.

Limited Browser Support

navigator.vibrate() is part of the Vibration API and is not Baseline. Support is strongest on Android Chromium browsers. Many desktop browsers expose the method with no hardware effect; Safari support has historically been limited or absent. Always feature-detect and test on a real phone.

Limited · Not Baseline

Navigator.vibrate()

Boolean → pulse vibration hardware with ms / pattern arrays.

Limited Not Baseline
Google Chrome Strong on Android; desktop often no haptic
Limited
Microsoft Edge Follow Chromium / device hardware
Limited
Opera Follow Chromium where available
Limited
Mozilla Firefox Android support; desktop limited
Limited
Apple Safari Historically unavailable / limited — feature-detect
Unavailable
Internet Explorer No Vibration API
Unavailable
vibrate() Limited

Bottom line: Detect the method, call from a user gesture, keep patterns short, cancel with vibrate(0), and never rely on haptics as the only feedback.

Conclusion

navigator.vibrate() is the Vibration API way to give short haptic feedback. Feature-detect it, call it from a user gesture, prefer brief patterns, and cancel with vibrate(0) when needed.

Continue with share(), unregisterProtocolHandler(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Call from a button click / tap
  • Feature-detect before vibrating
  • Keep patterns short and meaningful
  • Offer a “disable haptics” setting
  • Test on a real phone

❌ Don’t

  • Vibrate on page load or in a loop
  • Assume true means the user felt it
  • Use long noisy patterns for tiny UI events
  • Ignore Silent / DND limitations
  • Make critical UX depend only on vibration

Key Takeaways

Knowledge Unlocked

Five things to remember about vibrate()

Limited Vibration API — short haptic pulses from a user gesture.

5
Core concepts
📊 02

Support

Limited

Not Baseline
👋 03

Needs

user gesture

Activation
📈 04

Pattern

ms or array

On / pause
🚫 05

Cancel

vibrate(0)

Stop

❓ 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.
No. MDN does not mark it Deprecated, Experimental, or Non-standard. It is Limited availability (not Baseline). No status banner is required.
Sticky user activation is required. Call vibrate from a button click or similar UI interaction — not from page load or a timer alone.
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.
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.
Did you know?

If a vibration is already running, calling vibrate() again does not queue a second pattern — it halts the old one and starts the new pattern immediately.

Explore share() Next

Open the device’s native share sheet for URLs, text, and files.

share() →

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.

8 people found this page helpful