11

I have a web application that uses the browser's default monospace font. It's set up that way so that the user can pick their own. In Chrome, this works well, as it's easy to set the default fonts, but in Safari, they removed the option.

Is there some way for users to set default fonts in Safari?

3

As of Safari 12, all options for doing so have been removed:

  • The Appearance panel is (long) gone
  • The defaults keys are no longer respected
  • CSS @font-face definitions are limited to a built-in whitelist of local() values, ignoring any other fonts installed on the system, which is part of a broad package of anti-fingerprinting measures

Taken together, this means there is no way to change the defaults away from Times for serif, Helvetica for sans-serif, and Courier for monospace.


The only thing you can still do is create a user stylesheet to style various elements directly. So for example you could change the default font family from serif to sans-serif:

body { font-family: sans-serif }

Or you can even still name specific locally installed non-system fonts:

body { font-family: 'Open Sans' }

Unfortunately while this works reasonably well for changing the default document font, it is complicated to use the same approach to restyle every element that defaults to a monospace font. I am not sure CSS can even fully emulate the default behaviour for such elements at all – whereas it was previously easy to do so by using either defaults or a user stylesheet with a @font-face rule for monospace (which simply redefined what monospace meant without touching the default styling itself, and so allowed the default behaviour to apply to that other font).

I viscerally dislike reading large amounts of text set in Courier, so it looks like in the future I will have to use another browser to read RFCs

| improve this answer | |
  • Thanks for the update, Aristotle. Although Lri's answer was very good, it hasn't aged well, so I've have moved the check over to your answer to direct future visitors to the most current information. – Carl Smith Jan 13 at 17:03
  • Thanks. Yes, I used Lri’s answer for years; unfortunately, the music has now stopped. It’s… regrettable, to say the least, but that’s how it is. – Aristotle Pagaltzis Jan 14 at 22:00
  • "a broad package of anti-fingerprinting measures"—I realized that unfortunately this is why sites like Google can't use their default fonts such as Roboto when displaying content, even if it's installed on the User's system – Skeleton Bow Jun 26 at 23:28
13

The following information was correct when it was posted, but now only applies to obsolete versions of Safari.


There are unexposed preferences for changing the default fonts and font sizes:

defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2StandardFontFamily Georgia
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultFontSize 16
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2FixedFontFamily Menlo
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultFixedFontSize 14

Another option is to edit the CSS file that defines the default styles (look in Preferences > Advanced > Stylesheet), adding something like this, for example:

@font-face {
   font-family: monospace;
   src: local('Menlo');
}

That rule makes any element that uses font-family: monospace (as well as elements like <pre> and <code> by default) use Menlo. Just change the font name (being careful to keep the enclosing quotes) to whatever you prefer.

| improve this answer | |
  • 1
    Suddenly, it doesn't work for additional fonts installed via Font Book on Mojave (10.14.2) – Ilya Vassilevsky Feb 7 '19 at 11:59
  • See Aristotle Pagaltzis new answer (above). It's not great news. – Carl Smith Jan 13 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .