Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Auto Zoom in Input "Text" tag - Safari on iPhone

I made an HTML page that has an <input> tag with type="text". When I click on it using Safari on iPhone, the page becomes larger (auto zoom). Does anybody know how to disable this?

like image 463
Eduardo Montenegro Avatar asked Jun 07 '10 12:06

Eduardo Montenegro


People also ask

How do I stop Safari from zooming in iPhone?

Open the Settings app on the iPhone or iPad. Scroll down and choose the Safari browser from Settings. From Safari Settings, select the Page Zoom Safari option. Within the window, tap to select the Zooming level.

How do I stop Safari from zooming in?

In the viewport meta tag above:maximum-scale=1 fixes the maximum scale of the page to 1.0. This prevents Safari from auto-zooming while still allowing the user to zoom in manually.

How do I fix the zoom in input field on mobile devices?

Solution 1Set the window and body to a size that fills the screen-space, without exceeding it. This is why so many people have success with forcing input text-size to 16px; once you do that, its clear that you're WAY zoomed out.

How do I stop auto zoom?

There is no way to disable the auto zoom. If you want to see the maximum amount of the screen the only way to do so is to make the input as wide as the screen and use a single-column form.


2 Answers

You can prevent Safari from automatically zooming in on text fields during user input without disabling the user’s ability to pinch zoom. Just add maximum-scale=1 but leave out the user-scale attribute suggested in other answers.

It is a worthwhile option if you have a form in a layer that “floats” around if zoomed, which can cause important UI elements to move off screen.

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

like image 168
daxmacrog Avatar answered Sep 18 '22 05:09

daxmacrog


The browser will zoom if the font-size is less than 16px and the default font-size for form elements is 11px (at least in Chrome and Safari).

Additionally, the select element needs to have the focus pseudo-class attached.

input[type="color"], input[type="date"], input[type="datetime"], input[type="datetime-local"], input[type="email"], input[type="month"], input[type="number"], input[type="password"], input[type="search"], input[type="tel"], input[type="text"], input[type="time"], input[type="url"], input[type="week"], select:focus, textarea {   font-size: 16px; } 

It's not necessary to use all the above, you can just style the elements you need, eg: just text, number, and textarea:

input[type='text'], input[type='number'], textarea {   font-size: 16px; } 

Alternate solution to have the input elements inherit from a parent style:

body {   font-size: 16px; } input[type="text"] {   font-size: inherit; } 
like image 33
srikanth Avatar answered Sep 19 '22 05:09

srikanth