123

Are there CSS or other reasons why Safari/iPhone would ignore some font-size settings? On my particular website Safari on the iPhone renders some font-size:13px text larger than font-size:15px text. Does it maybe not support font-size on some elements?

Kevin Hakanson
  • 41,386
  • 23
  • 126
  • 155
Alex
  • 75,813
  • 86
  • 255
  • 348

5 Answers5

282

Joe's response has some good best practices in it, but I think the problem you're describing centers around the fact that Mobile Safari automatically scales text if it thinks the text will render too small. You can get around this with the CSS property -webkit-text-size-adjust. Here's a sample of how to apply this to your body, just for the iPhone:

@media screen and (max-device-width: 480px){
  body{
    -webkit-text-size-adjust: 100%;
  }
}
Raphael Schweikert
  • 18,244
  • 6
  • 55
  • 75
David Kaneda
  • 5,320
  • 1
  • 21
  • 14
  • 2
    Just ran into this issue. This little media screen hack works flawlessly. I'm going to start incorporating it into my CSS starter file. – Throttlehead Jan 30 '13 at 16:32
  • 2
    Make sure to use the media query. It seems that this can make some text difficult to read: [Beware of -webkit-text-size-adjust:none](http://www.456bereastreet.com/archive/201011/beware_of_-webkit-text-size-adjustnone/) – Gemmu Feb 13 '15 at 12:46
  • 15
    Answer should be updated to `-webkit-text-size-adjust: 100%` - this avoids the automatic update, but allows user initiated zoom. [(source)](http://blog.55minutes.com/2012/04/iphone-text-resizing/) – Shawn Erquhart Jan 17 '17 at 19:03
  • I think there's a further issue: If you do some media query like '@media screen and (min-width: 475px){h1 {font-size: 3em;}}': e.g. iPhone6 is effectively 750px so this rule applies... However with high pixel-ratio, for all the rest it acts as if screen about 320px wide... so you would want the "less-than-475px"-rules to apply? – user3445853 Oct 05 '20 at 19:33
  • also add -moz-text-size-adjust: 100%; and text-size-adjust:100%; to maximize compatibility – Joan Galmés Riera May 18 '23 at 16:11
  • any idea to make it work on safari macOs? – bernard Jul 27 '23 at 09:43
18

Use 100% instead of None.

normalize.css includes this

user3276706
  • 181
  • 1
  • 2
14

Also, make sure you are setting the initial zoom setting to 1 in your viewport meta tag:

<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
johnpolacek
  • 2,599
  • 2
  • 23
  • 16
1

Also check if you don't have a "width/height" set to the elements you're manipulating, Safari gives sizing precedence over font size in svg's, Chrome and FF don't, it seems, currently at least.

marebuffi
  • 41
  • 1
  • 6
0

I had the same problem, turns out in the original CSS there was this line:

-webkit-text-size-adjust: 120%;

I had to change it to 100%, and everything was smooth. No need to change all px to em or %%.

me1974
  • 99
  • 1
  • 12