Vibrating your phone with JavaScript ๐Ÿ“ฑ

Vibrating your phone with JavaScript ๐Ÿ“ฑ

May 28, 2022ยท

1 min read

Play this article

In this article we are going to vibrate mobile phones with JavaScript Vibration API.

JavaScript is an amazing language


The navigator.vibrate method pulses the vibration hardware on the device if such device is compatible. If device is not compatible, no effect will take place.

The method works in the following structure,


So, this was a little explanation on the navigator.vibrate method. Now let's deal with some easy examples.


const vibrate = () => {

This will vibrate the hardware for 500ms.

const vibrateTwoTimes = () => {
  window.navigator.vibrate([200, 100, 200])

In this example, vibration will occur two times for 200ms with a gap of 100ms.


I hope you have found this article useful. Thank you for reading!

Let's Connect