Prevent iPhone from zooming in on select
in web-app
No more unexpected Safari zooming. Use either of these methods:
or,
But wait, there's a bit more to the story. Let's investigate...
The critical balance: Usability vs Accessibility
Resorting to user-scalable=no
may fix the immediate zoom issue, but think about the poor souls who rely on zooming for better readability. We need to straddle the fence of usability and accessibility. This requires a technique that allows our cake to have it, too. Yes, that's responsive typography.
Being responsive means scaling the font-size on larger screens for better readability, but not triggering the zoom on iPhones. Ohh, Apple, why do you make this challenging?
Responsive Typography: Mobile-first Approach
We begin with a mobile-first design, setting the select
font-size at 16px for our small-screen friends, and whip out our media queries for the big-screen gang:
This way, you prevent zoom on mobile gadgets, and the desktop users are not complaining about oversized fonts. Whew!
With Great Text Size Comes Great Difficulty
To be honest, setting 16px on mobile can ruin your design's aesthetics and might not sit well. It feels like feet jammed into uncomfortable shoes. So, CSS transform scale comes to the rescue shrinking the size visually while not triggering the zoom.
Here begins the game of adjustments, adjusting padding and other styles to make the select box look presentable and consistent with the rest of your design.
Implementing The Detective’s Magnifying Glass
Perhaps you'll need to nudge a few more styles to keep the layout from imploding:
This may seem like finesse vs function - adding more complexity to your CSS just for aesthetics. Yes, but we can't afford to ignore either.
The Big Picture: Usability Enhancement
Remember, all of this hoopla is specifically for iPhones. Other devices or browsers may not play along with these styles or might march to their own tunes causing unexpected results. Be sure to test across multiple browsers and devices to ensure universal peace.
Constant browser updates can make a coder's life interesting. So keep an eye on the release notes especially for Safari on iPhone, you'll never know when they decide to throw a curveball at us. Checking out resources like WebKit's blog can help you stay on your toes.
As they say, shoot for the moon, and if you miss, you'll be among the stars. So aim for functionality first for all users and sprinkle on enhancements for specific scenarios. Use feature queries to up your game:
Was this article helpful?