<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: jasperreddin</title>
    <description>The latest articles on Forem by jasperreddin (@jasperreddin).</description>
    <link>https://forem.com/jasperreddin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F11002%2Fb082fcea-aa1f-4500-95c7-a43831273809.jpg</url>
      <title>Forem: jasperreddin</title>
      <link>https://forem.com/jasperreddin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jasperreddin"/>
    <language>en</language>
    <item>
      <title>Disabling Viewport Zoom on iOS 14 Web Browsers</title>
      <dc:creator>jasperreddin</dc:creator>
      <pubDate>Sun, 11 Apr 2021 20:13:52 +0000</pubDate>
      <link>https://forem.com/jasperreddin/disabling-viewport-zoom-on-ios-14-web-browsers-l13</link>
      <guid>https://forem.com/jasperreddin/disabling-viewport-zoom-on-ios-14-web-browsers-l13</guid>
      <description>&lt;p&gt;I recently answered a question on Discord on how to disable double-tap to zoom on iOS browsers. I looked this problem up on Google, and most people said to use the viewport meta tag. Except that was four years ago and it seems that Safari no longer respects those tags. &lt;/p&gt;

&lt;p&gt;Many are using Javascript to solve this, but that could be unreliable in many ways.&lt;/p&gt;

&lt;p&gt;But now, since Safari 13, there is a way to disable viewport zooming.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;touch-action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pan-y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What the &lt;code&gt;touch-action&lt;/code&gt; property does is it disables all touch events going to the selected element(s) except for the value specified. So by setting the property to &lt;code&gt;pan-y&lt;/code&gt; for the whole body, we're only letting the user pan up and down, no matter where they initiate the touch. Any other touch events, whether it be a double tap, a pinch, or even a pan left or right, will be ignored. &lt;/p&gt;

&lt;p&gt;You can read more about the &lt;code&gt;touch-action&lt;/code&gt; CSS property &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;If you need to allow the user to pan both up or down &lt;em&gt;and&lt;/em&gt; left or right, you can add &lt;code&gt;pan-x&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;touch-action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pan-y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pan-x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;If you have just &lt;code&gt;pan-y&lt;/code&gt; turned on in your body selector, and you have smaller viewports inside your document where there will be horizontal scrolling, you can override the property value in the child element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.childViewPortElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;scroll&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="err"&gt;...&lt;/span&gt;
  &lt;span class="py"&gt;touch-action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pan-y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pan-x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Fair Warning
&lt;/h2&gt;

&lt;p&gt;In my testing I found out that on iOS, viewport zoom is fully disabled when the &lt;code&gt;touch-action&lt;/code&gt; property is restricted like this. This applies even to automatic zooms that the browser performs, such as when the user taps on a text box with a font size smaller than 16px. &lt;/p&gt;

&lt;p&gt;However, if even one element in the body has &lt;code&gt;touch-action&lt;/code&gt; set to &lt;code&gt;pinch-zoom&lt;/code&gt; or &lt;code&gt;manipulation&lt;/code&gt; the browser will perform automatic zooms when tapping on small text boxes.&lt;/p&gt;

&lt;p&gt;So be mindful of that, if you do have to enable manipulation or pinch-zoom events.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>ios</category>
    </item>
  </channel>
</rss>
