Vibration API - Web APIs | MDN

archived 17 Sep 2025 10:09:33 UTC
  1. Web
  2. Web APIs
  3. Vibration API

Vibration API

Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Most modern mobile devices include vibration hardware, which lets software code provide physical feedback to the user by causing the device to shake. The Vibration API offers Web apps the ability to access this hardware, if it exists, and does nothing if the device doesn't support it.

Concepts and usage

Vibration is described as a pattern of on-off pulses, which may be of varying lengths. The pattern may consist of either a single integer, describing the number of milliseconds to vibrate, or an array of integers describing a pattern of vibrations and pauses. Vibration is controlled with a single method: Navigator.vibrate().

A single vibration

You may pulse the vibration hardware one time by specifying either a single value or an array consisting of only one value:
js
navigator.vibrate(200);
navigator.vibrate([200]);
Both of these examples vibrate the device for 200 ms.

Vibration patterns

An array of values describes alternating periods in which the device is vibrating and not vibrating. Each value in the array is converted to an integer, then interpreted alternately as the number of milliseconds the device should vibrate and the number of milliseconds it should not be vibrating. For example:
js
navigator.vibrate([200, 100, 200]);
This vibrates the device for 200 ms, then pauses for 100 ms before vibrating the device again for another 200 ms.
You may specify as many vibration/pause pairs as you like, and you may provide either an even or odd number of entries; it's worth noting that you don't have to provide a pause as your last entry since the vibration automatically stops at the end of each vibration period.

Canceling existing vibrations

Calling Navigator.vibrate() with a value of 0, an empty array, or an array containing all zeros will cancel any currently ongoing vibration pattern.

Continued vibrations

Some basic setInterval and clearInterval action will allow you to create persistent vibration:
js
let vibrateInterval;

// Starts vibration at passed in level
function startVibrate(duration) {
  navigator.vibrate(duration);
}

// Stops vibration
function stopVibrate() {
  // Clear interval and stop persistent vibrating
  if (vibrateInterval) clearInterval(vibrateInterval);
  navigator.vibrate(0);
}

// Start persistent vibration at given duration and interval
// Assumes a number value is given
function startPersistentVibrate(duration, interval) {
  vibrateInterval = setInterval(() => {
    startVibrate(duration);
  }, interval);
}
Of course, the snippet above doesn't take into account the array method of vibration; persistent array-based vibration will require calculating the sum of the array items and creating an interval based on that number (with an additional delay, probably).

Interfaces

Extensions to other interfaces

Causes vibration on devices with support for it. Does nothing if vibration support isn't available.

Specifications

Specification
Vibration API​ (external)

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Node.js
vibrate
Chrome – Full support
Chrome 32 (Release date: ⁨2014-01-14⁩)
footnote Full support
Edge – Full support
Edge 79 (Release date: ⁨2020-01-15⁩)
footnote Full support
Firefox – No support
Firefox 11 – 15 (Release date: ⁨2012-03-13⁩)
prefix
prefix Implemented with the vendor prefix: ⁨moz⁩
Firefox – No support
Firefox 16 – 128 (Release date: ⁨2012-10-09⁩)
footnote Removed in ⁨129⁩ and later footnote Until Firefox 26 included, when the vibration pattern was too long or any of its elements too large, Firefox threw an exception instead of returning false (bug 884935). footnote From Firefox 32 onwards, when the vibration pattern is too long or any of its elements too large, it returns true but truncates the pattern (bug 1014581). footnote Beginning in Firefox 72, this is not supported in cross-origin iframes.
Opera – Full support
Opera 19 (Release date: ⁨2014-01-28⁩)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 32 (Release date: ⁨2014-01-15⁩)
footnote
footnote Beginning in Chrome 55, this is not supported in cross-origin iframes. footnote Beginning in Chrome 60, this method requires a user gesture. Otherwise it returns false.
Firefox for Android – No support
Firefox for Android 14 – 15 (Release date: ⁨2012-06-26⁩)
prefix
prefix Implemented with the vendor prefix: ⁨moz⁩
Firefox for Android – No support
Firefox for Android 16 – 68 (Release date: ⁨2012-10-09⁩)
footnote Until Firefox 26 included, when the vibration pattern was too long or any of its elements too large, Firefox threw an exception instead of returning false (bug 884935). footnote From Firefox 32 onwards, when the vibration pattern is too long or any of its elements too large, it returns true but truncates the pattern (bug 1014581).
Firefox for Android – Partial support
Firefox for Android 79 (Release date: ⁨2020-07-28⁩)
footnote Partial support footnote Vibration is disabled. If the window is visible, then navigator.vibrate() returns true, but no vibration takes place (regardless of hardware support). Originally, the intent was to disable it for cross-origin frames only (bug 1591113), but the feature was not re-enabled due to abuse concerns (bug 1653318).
Opera Android – Full support
Opera Android 19 (Release date: ⁨2014-01-28⁩)
footnote
footnote Beginning in Opera 42, this is not supported in cross-origin iframes. footnote Beginning in Opera 47, this method requires a user gesture. Otherwise it returns false.
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 2 (Release date: ⁨2014-10-17⁩)
footnote
footnote Beginning in Chrome 55, this is not supported in cross-origin iframes. footnote Beginning in Chrome 60, this method requires a user gesture. Otherwise it returns false.
WebView Android – Full support
WebView Android 4.4.3 (Release date: ⁨2014-06-02⁩)
footnote
footnote Beginning in version 55, this is not supported in cross-origin iframes. footnote Beginning in version 60, this method requires a user gesture. Otherwise it returns false.
WebView on iOS – No support
WebView on iOS
footnote No support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.
Full support Full support
Partial support Partial support
No support No support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also

Help improve MDN

Learn how to contribute
This page was last modified on by MDN contributors.
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%