Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari shows larger font size than other broswers

Tags:

html

css

safari

I'm working on a website, on which fonts are much larger on Mac's Safari than on the other browsers,

The website is using the 'Open Sans' font from Google Fonts.

Example, this a CSS snippet for titles:

h2.protitlesnbm{
    color: #404040;
    font-size: 22px;
    text-transform: uppercase;
    float: none;
} 

This shows up like below on Chrome, Firefox and IE:

Example showing the text in regular font size.

But on Mac's Safari, it is shown like this:

The same example on Safari, now the text is bold

Somehow, Safari seems to add 1px for all fonts.

Can anyone help me to fix this issue?

like image 350
Suneth Kalhara Avatar asked Oct 15 '18 11:10

Suneth Kalhara


People also ask

How to change the default font size in Safari?

A web page in Safari using the 24-point minimum font size. If you change your mind later and want the smaller font sizes back, click “Safari” in the menu bar and navigate to Preferences > Advanced, and then uncheck the “Never Use Font Sizes Smaller Than” option. Alternately, you can simply select a smaller font size from the menu.

How to make text bigger in Safari on Mac?

Safari will remember your settings until you clear your History. Or you can go to the View menu and hold down the Option key while you select Make Text Bigger or Make Text Smaller. You can increase or decrease the zoom level – both text and images – of pages that you view in Safari on macOS Sierra.

How to change font size on MacBook Air?

To get started, open the Safari browser on your Mac. Click “Safari” in the top menu bar and choose “Preferences” from the drop-down menu. In the “Advanced” tab, locate the “Accessibility” section and click the check mark next to “Never Use Font Sizes Smaller Than.” In the drop-down menu, choose between “14,” “18,” or “24” -point font sizes.

How to increase or decrease the zoom level in Safari on macOS?

You can increase or decrease the zoom level – both text and images – of pages that you view in Safari on macOS Sierra. Safari will remember your settings until you clear your History. Or go to the View menu and select Zoom in or Zoom out. If you clear your Safari history, websites will go back to their default font size or zoom level.


2 Answers

You could try using

-webkit-font-smoothing: subpixel-antialiased;

or

-webkit-font-smoothing: antialiased;
like image 128
Chillie Avatar answered Oct 01 '22 13:10

Chillie


You can always use JavaScript check if the browser is Safari, and if it is, just minimize the font sizes by 1px. I know that this is not a conventional way of doing things, but as long as it works:

var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) {
    return p.toString() === "[object SafariRemoteNotification]";
})(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification));

This method was taken from Javascript - How To Detect Browsers And its explanation:

Safari: A unique naming pattern in its naming of constructors. This is the least durable method of all listed properties and guess what? In Safari 9.1.3 it was fixed. So we are checking against SafariRemoteNotification, which was introduced after version 7.1, to cover all Safaris from 3.0 and upwards.

In order to change font sizes, there is a deprecated method that could still work:

document.body.fontSize(-1);

If not, try CSS Relative Font Sizes:

document.body.style.fontSize = ""; //Either Enter Percentages (90%) or EM
//EM Will Automatically Change Font-Size According To Browser
//%-ages Will Change Values Through Math (110% of 16px)

Hope that helps!

like image 32
Da Mahdi03 Avatar answered Oct 01 '22 13:10

Da Mahdi03