Apple - Is there a way to set the *default* monospace font in Safari?

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.


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…

Tags:

Css

Safari