Many consumer web sites have done a fantastic job of deploying mobile web versions of their sites. However, over the last year I have heard an increasing number of complaints about websites specifically designed for mobile: you simply can’t adjust the font size. Depending on the device’s screen size, this can potentially cause painful choices: either deal with (usually) tiny font sizes and struggle to read content, or go to the full web site and be relegated to panning, zooming and rotating between portrait and landscape mode to try and fit as much content as possible onto a tiny screen.
To me, the solution is easy: allow users to set their own font-size. Here’s an example of settings I’m referring to, specifically setting the viewport’s user-scalable property to ‘no’ is what’s causing the problem:
<meta name="viewport" content="width=device-width, user-scalable=no">
There are certainly use cases, such as mapping applications, were you might want to prevent user scaling because it will affect other components inside the application. However, if there aren’t any components affected by pinch zoom then you most likely can set the user-scalable property to yes, or simply omit the property.
My first suggestion is provide users with the ability to adjust the font size. Here is an example that will let the user adjust font size for a specific DIV:
<meta name="viewport" content="width=device-width"> <script> var up = 1; var down = -1; var elementSize = document.getElementById(“someDiv”) .style.fontSize; function increaseFont(){ up++; elementSize = up + “px”; } function decreaseFont(){ down--; elementSize = down + “px”; } function resetFont(){ elementSize = “14px”; } </script>
Another option is to combine the above suggestion with media queries to adjust font-size automatically based on screen size, pixel ratio and/or min-resolution. Here is one example:
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) { body{ font-size: 16px; } }
Other examples of media queries can be found here: css-tricks.com.