Search code examples
htmlcssresponsive-designfrontenduser-experience

How to disable double-tap zoom on Safari mobile?


How can double-tap zoom be disabled on Safari mobile?

There are some rules for default behaviour: With text it somehow depends on font-size. Other types of elements also allow to be double tapped and usually perform a zoom then (e. g. img).

But the entire double-tap zoom should be disabled.

These were common approaches:

  • Applying touch-action: manipulation to *; does not work at all.
  • Applying touch-action: none to *; seems to disable zooming back out from the zoomed-in position…
  • <meta name="viewport" ...>; the browser ignores it.
  • Then, there were some JavaScript/jQuery solutions but none seemed to work at all or work reliably.

Solution

  • document.ondblclick = function (e) {
        e.preventDefault();
    }
    

    That's literally it. No special tricks needed lol. Tested on Safari iOS.