Skip to main content
haptic is the main export of ios-haptics. When called, it triggers a single haptic tap on iOS (via the checkbox switch trick) or a 50ms vibration on Android (via navigator.vibrate). Import

haptic()

Triggers a single haptic feedback event. Signature: haptic(): void
On iOS, haptic() creates an <input type="checkbox" switch> element wrapped in a hidden label, appends it to document.head, clicks it, then immediately removes it. This exploits the native checkbox switch interaction to produce a haptic tap. On Android, it calls navigator.vibrate(50) instead.

haptic.confirm()

Triggers two rapid haptic feedback events — suitable for confirmation actions. Signature: haptic.confirm(): void On iOS, calls haptic() twice, 120ms apart. On Android, calls navigator.vibrate([50, 70, 50]).
Use this for success confirmations, form submissions, or positive user actions.

haptic.error()

Triggers three rapid haptic feedback events — suitable for error states. Signature: haptic.error(): void On iOS, calls haptic() three times, 120ms apart (at 0ms, 120ms, and 240ms). On Android, calls navigator.vibrate([50, 70, 50, 70, 50]).
Use this for validation errors, failed operations, or warning states.

Error handling

The internal _haptic() function is wrapped in a try/catch block — any DOM errors are silently ignored. The library will never throw, so it is always safe to call without additional error handling.