Vibration API

On this page 7

The Vibration API is a browser interface that lets a web page drive the vibration motor of a device through a single method, navigator.vibrate(). In the Mobile web, it gives sites and progressive web apps a way to provide haptic feedback for events such as a completed payment, an invalid form entry or an incoming alert, without a native application.

The interface is deliberately minimal: a page can request a single pulse or a pattern of pulses and pauses, measured in milliseconds, and can cancel an active vibration. It offers no control over intensity, frequency or waveform, and its availability depends heavily on the browser and the operating system, which shapes how responsible developers use it in Mobile products.

How the Vibration API drives the device motor

The Vibration API works by passing a duration or a pattern array to navigator.vibrate(), which the browser hands to the platform’s haptic service. A single number such as navigator.vibrate(200) requests a 200-millisecond pulse. An array such as [100, 50, 100] alternates vibration and pause intervals, starting with vibration, so this example produces two short buzzes separated by a brief gap.

The method returns a Boolean value: true when the request was accepted and false when the pattern was invalid or the browser refused it. A return value of true does not guarantee physical vibration, because the device may be silenced, in a battery saver mode or simply lacking a motor. Calling navigator.vibrate(0) or passing an empty array cancels any running pattern, and a new call always replaces the previous pattern instead of queuing behind it.

The following table summarizes the forms of the argument and how browsers interpret each one.

ArgumentExampleResult
Single numbernavigator.vibrate(300)One pulse of 300 ms
Pattern array[200, 100, 200]Vibrate, pause, vibrate
Zeronavigator.vibrate(0)Stops current vibration
Empty arraynavigator.vibrate([])Stops current vibration
Odd-length array[100, 50, 100, 50, 100]Ends on a vibration interval
Argument forms accepted by navigator.vibrate()

Specification, rules and browser support

The Vibration API was standardized by the W3C as a Recommendation, and its processing model defines how values are normalized. Browsers may truncate overly long patterns and clamp very long intervals to an implementation-defined maximum, so a pattern that runs for minutes is unlikely to behave as written. The specification also requires that vibration stops when the page becomes hidden, for example when the user switches tabs or locks the screen.

Abuse prevention is a central design concern. Chromium-based browsers require sticky user activation, meaning the user must have tapped, clicked or pressed a key on the page before any call succeeds, and they block calls from cross-origin iframes such as embedded advertisements. Without that gesture, the call is ignored and a console warning appears.

Support varies sharply across platforms, as the following table shows. Developers should treat the API as a progressive enhancement and never as a dependency.

Browser familySupport statusPractical note
Chrome and Chromium on AndroidSupportedRequires prior user gesture
Samsung InternetSupportedFollows Chromium behavior
Firefox on AndroidLimited or removedDo not rely on it
Safari on iOS and iPadOSNot supportedMethod is absent
Desktop browsersMethod may existUsually no motor to drive
Typical support situation by browser family

Because Safari on iOS lacks the method entirely, any feature that relies on vibration silently disappears for a large share of Mobile users. Feature detection with 'vibrate' in navigator is the minimum safeguard, and the visual or audio feedback should remain complete on its own.

The Vibration API is one of several device interfaces in the Mobile web that bring hardware capabilities to pages. It is output-only: it sends a signal to the user, while neighbors such as Touch events and Device orientation events read input from the user or the device. The table below places it beside those related interfaces.

InterfaceDirectionMain purpose
Vibration APIOutput to userHaptic pulses and patterns
Touch eventsInput from userFinger contact and gestures
Device orientation eventsInput from sensorsTilt and rotation data
Screen Orientation APIRead and lockPortrait or landscape state
Mobile web pushOutput via systemNotifications, optionally vibrating
Vibration API compared with neighboring web interfaces

Native platforms provide much richer haptics. Android offers amplitude control and predefined effects through its vibrator service, and iOS offers a dedicated haptic engine with transient and continuous events. The web interface exposes only on and off timing, so a web app cannot reproduce the crisp, tuned taps that users feel in well-designed native applications. Web push notifications can also carry a vibration pattern, but that path is controlled by the notification system rather than by the page itself.

Designing useful haptic feedback on the web

Effective use of the Vibration API rests on short, meaningful and infrequent pulses tied directly to a user action. Most interface confirmations work well between 10 and 50 milliseconds, while warnings and alerts can use longer pulses or a two-part pattern. Long or repeated buzzing tends to feel like an error or a malfunction rather than feedback.

The following decision table maps common situations to a reasonable pattern and the reason behind it.

SituationSuggested patternReason
Button or toggle confirmation15 to 30 msSubtle tap, not distracting
Form validation error[50, 50, 50]Double pulse signals a problem
Completed transaction[30, 80, 60]Distinct success rhythm
Timer or alarm in a web app[400, 200, 400]Noticeable when attention is elsewhere
Game collision or hit40 to 80 msImmediate physical response
Pattern choices for common interface events
  • Run feature detection before calling the method and keep the interface fully usable without it.
  • Provide a user setting to disable haptics, which respects personal preference and accessibility needs.
  • Call the method only inside a user gesture handler so that Chromium browsers accept it.
  • Pair vibration with a visible state change, so that deaf, hard of hearing and motor-impaired users receive the same information.

Limitations, risks and common mistakes

The main limitation of the Vibration API is its coarse, binary control: it cannot express strength or texture, and identical patterns feel different on different motors. Eccentric rotating mass motors respond slowly and blur short pulses, while linear resonant actuators reproduce them more crisply, so testing on several real devices is essential.

Misuse also carries privacy and annoyance risks. Early abuse by advertisements and scam pages, which buzzed phones to simulate urgent alerts, is the reason browsers now demand user activation. Researchers have also discussed vibration as a weak fingerprinting or side channel signal, which partly explains why some browser vendors have reduced or removed support.

MistakeConsequenceFix
Calling on page loadCall is blocked silentlyTrigger only after a tap
Assuming iOS supportFeature missing for many usersUse feature detection
Very long patternsTruncated or annoying outputKeep pulses brief
Vibration as sole signalInformation lost for some usersAdd visual feedback
No opt-out settingUsers disable notifications or leaveOffer a haptics toggle
Frequent mistakes and how to correct them

In plain words

The Vibration API lets a website make a phone buzz, much like an app does when a message arrives. The page can ask for one short buzz or a little rhythm of buzzes and pauses. It is a gentle nudge you can feel, useful when a button press worked or something went wrong.

There are clear limits. Many iPhones and iPads will not buzz at all for websites, and most browsers only allow it after you have touched the page, which stops annoying ads from shaking your phone. Good sites use it lightly and always show the same message on screen.

A real-world example

A regional public transit operator runs a progressive web app that riders use to scan tickets at station gates. When a rider taps the scan button and the gate reader accepts the ticket, the app calls navigator.vibrate(30) for a brief confirmation tap. When the ticket is expired, it plays the pattern [60, 60, 60] and turns the screen red with a clear message.

Riders on Android phones feel the difference between success and failure without looking at the screen, which speeds up crowded gate lines during rush hour. Riders on iPhones see the same green or red screen and hear a short tone, so no one loses information. The team also adds a haptics toggle in settings after a few riders report preferring silence. The result is faster, more confident gate passage for everyone, with vibration acting as a helpful extra rather than a requirement.