Navigator: vibrate() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The vibrate() method of the Navigator interface pulses the vibration hardware on the device, if such hardware exists. If the device doesn't support vibration, this method has no effect. If a vibration pattern is already in progress when this method is called, the previous pattern is halted and the new one begins instead.

If the method was unable to vibrate because of invalid parameters, it will return false, else it returns true. If the pattern leads to a too long vibration, it is truncated: the max length depends on the implementation.

Some devices may not vibrate if they are in Silent mode or Do Not Disturb (DND) mode. To ensure vibration works, make sure these modes are turned off and that vibration is enabled in the system settings.

Syntax

js
vibrate(pattern)

Parameters

pattern

Provides a pattern of vibration and pause intervals. Each value indicates a number of milliseconds to vibrate or pause, in alternation. You may provide either a single value (to vibrate once for that many milliseconds) or an array of values to alternately vibrate, pause, then vibrate again. See Vibration API for details.

Passing a value of 0, an empty array, or an array containing all zeros will cancel any currently ongoing vibration pattern.

Return value

A boolean.

Security

Sticky user activation is required. The user has to interact with the page or a UI element in order for this feature to work.

Examples

js
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.

Specifications

Specification
Vibration API
# dom-navigator-vibrate

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