I am designing a mobile site, and I'm wondering what I should set the font size as. Any suggestions?
4 Answers
Like any normal web design, it's worth staying away from pixel sizes so if a user really needs larger text they can still use your site.
Unless you're targetting a specific group of phones that you can test, it's best to let the OS and browser handle the size. font-size: medium; should be fine for content, and then you should be able to make em based adjustments for larger or smaller text.
That will give a better user experience across a larger amount of devices.
If you want to optimise the experience, then it all depends on your content and what devices you're targeting. The only way you'll only find the optimal size is by testing.
- 638
- 4
- 8
Setting it to somewhere between 18-24pt (or 150-200% if you prefer) will probably give the best compromise results on iPhone and Android. From my testing, mobile browsers totally ignore what the standards say on relative vs. absolute and default to a size that attempts to display a page originally formatted for a full size computer (i.e. just barely readable if you're a teenager).
Here are my results on font size in different mobile browsers
- 171
- 2
-
Very interesting collection of results, even though I'd advice against specifying anything font related in pixels any more. – kontur Dec 27 '12 at 20:36
-
This article says to only use
pxandem: https://www.w3.org/Style/Examples/007/units.en.html#font-size Am I misinterpreting the context, is this article out of date, etc.? I'm honestly asking because I don't know. – Daniel Kaplan Feb 23 '23 at 21:25
Screen densities and UIs come in a wide range of flavors. So it's really a crapshoot. But if it's a UI catering to mobile devices, it probably doesn't hurt to err on the larger size.
- 41,799
- 5
- 81
- 142
It should be the default font-size!
Don't set it at all, the browser will set the root element font-size as the default (typically equivalent to 16px) for that device. This way you don't have to second guess either the OS / device creators or your users.
If you really feel that you should set something, set it at the default.
html {font-size: 100%}.
- 412
- 2
- 7
-
This is not a good advice, the default font size is based on the default font that the browser uses, if you use a different font the default font size may not appropriate. Not to mention that the default font size, might not be be aligned with other style constants in the design like padding, borders, and all the other general stuff – ehab Jun 14 '20 at 11:35
-
div {font-size: 80%}then you are going to run into inheritance issues when the HTML devs nest a DIV 3 deep--that's a case where px measurements are going to be the saner option. – DA01 Jun 02 '11 at 07:05font-size: medium;is the default. Given that, IMHO, it's preferable to excludefont-size: medium;when it would be the default value anyway. – Daniel Kaplan Feb 23 '23 at 21:32