Skip to main content
Install ios-haptics and wire it up to a button click in four steps.
1

Install ios-haptics

npm install ios-haptics
2

Import haptic

import { haptic } from 'ios-haptics'
3

Trigger a haptic on a button click

Pass haptic directly as an event listener, or call it inside your handler.
const button = document.querySelector('button')
button.addEventListener('click', () => {
  haptic()
})
4

Try the different haptic types

ios-haptics exposes three feedback patterns based on context.
// Single tap — general interaction feedback
haptic()

// Double tap — use for successful confirmations
haptic.confirm()

// Triple tap — use for errors or destructive actions
haptic.error()

Complete example

A full TypeScript example with a button that cycles through all three haptic types.
import { haptic } from 'ios-haptics'

const button = document.querySelector<HTMLButtonElement>('#haptic-btn')
const status = document.querySelector<HTMLSpanElement>('#status')

let step = 0

button?.addEventListener('click', () => {
  if (step === 0) {
    haptic()
    status!.textContent = 'Single tap'
    step = 1
  } else if (step === 1) {
    haptic.confirm()
    status!.textContent = 'Double tap (confirm)'
    step = 2
  } else {
    haptic.error()
    status!.textContent = 'Triple tap (error)'
    step = 0
  }
})
Haptics only fire on physical iOS and Android devices. They are silently ignored on desktop browsers and simulators, so you can safely call them without any environment checks.

Next steps

API reference

Full documentation for haptic(), haptic.confirm(), haptic.error(), and supportsHaptics.

How it works

Learn about the Safari checkbox switch trick that powers ios-haptics under the hood.