files/en-us/web/api/navigator/vibrate/index.md
{{APIRef("Vibration API")}}
The vibrate() method of the {{domxref("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.
vibrate(pattern)
pattern
Passing a value of 0, an empty array, or an array containing all zeros
will cancel any currently ongoing vibration pattern.
A boolean.
Sticky user activation is required. The user has to interact with the page or a UI element in order for this feature to work.
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}}
{{Compat}}