System Font Stack
systemfontstack.com
systemfontstack.com
some of them even come with annotations as to why they make the choices they make.
Github's font stack is
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Noto Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
VS Code:
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif
probably more "native" on mobile:
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif;
apparently all modern browsers have this new shortcut that make it as simple as:
font-family: ‘system-ui’, sans-serif;
@ff-sans:
-apple-system, BlinkMacSystemFont, // San Francisco on macOS and iOS
"Segoe UI", // Windows
"Liberation Sans", // Linux
sans-serif; // The final fallback for rendering in sans-serif.
@ff-serif: Georgia, Cambria, "Times New Roman", Times, serif;
@ff-mono:
ui-monospace, // San Francisco Mono on macOS and iOS
"Cascadia Mono", "Segoe UI Mono", // Newer Windows monospace fonts that are optionally installed. Most likely to be rendered in Consolas
"Liberation Mono", // Linux
Menlo, Monaco, Consolas, // A few sensible system font choices
monospace; // The final fallback for rendering in monospace.
[1]: https://github.com/StackExchange/Stacks/pull/642/files[2]: https://meta.stackexchange.com/questions/364048/we-are-switc...
It's mostly Helvetica based: San Francisco is the Apple knock off of Helvetica and Liberation Sans is a knock off of Arial which is a knock off of Helvetica. Only Segoe UI isn't Helvetica.
[1]: https://fedoraproject.org/wiki/Changes/DefaultToNotoFonts
font-family: system-ui, -apple-system, sans-serif;
Is really all you need these days. That covers all modern browsers, and older browsers will just fall back to whatever sans-serif is.> It turns out that the value of system-ui in fact not only depends on the version of the current OS, but the language of the OS as well.
I'm pretty sure the font choosing algorithm takes into account the "lang" attribute as well. lang attribute and the system language are probably used to determine the fallback order. For example, on Windows 10+ with system font stack without system-ui: [0], [1]
For Han characters:
- lang="en" + system lang en -> "Chinese" font
- lang="en" + system lang ja -> "Japanese" font
- lang="ja" + system lang en -> "Japanese" font
For Hiragana, Katakana:
- lang="en" + system lang en -> "Japanese" font
which is reasonable enough but can be surprising I think. This can be confusing when you care enough about how the Han unified characters look but can't control the lang attribute (for example in Discord messages).
[0] https://jsfiddle.net/6gfyrpv0/
[1] https://momdo.hatenablog.jp/entry/20200802/1596376257
Side note, if the system lang is en and on Windows 10+, Japanese Github markdown text will be shown in two fonts with different "weights" [3]. It looks fine if your system lang is Japanese. I wonder if it's possible to set/guess a custom lang attribute for user/repo/markdown document.
Like if you're on a Japanese OS but your language preferences are English, the default sans-serif font is a Japanese typeface that often doesn't display Roman alphabets that nicely.
Please specify your environment. I use Japanese OS and I haven't found a single OS/browser combo would do that.
Use Windows as an example, sans-serif by default = Arial for Chrome and Firefox for English content.
And as a bonus, you can even adjust the default sans-serif font in browser setting to your like; while with these hard-coded CSS, you can't.
Using plain sans-serif, I get Hiragino Kaku Gothic ProN as my default font instead of something nice like Helvetica Neue.
Because I feel like the former is meant to have Japanese fonts even for Latin glyphs for consistency's sake, but I understand that some people do prefer the other way.
And indeed, MacOS system font by default is like that. Windows is the opposite, though (everything is in Meiryo UI or whatever it's now called.) (Not sure if it's changed in Win11 either.)
Not the OP, but I'm sure it's webpages that don't have the lang attribute at all, which is why macOS used the Japanese font stack instead of the English one.
Furthermore, Firefox has a heuristic lang detection algorithm (!) based on content. I wrote an article about it 10 years ago, but not sure if it has been changed.
Uhh, let me check...
> MacOS Monterey, default system language is Japanese but obviously I browse a lot of English websites.
I don't think that OP ever stated that their browser is in English, just saying that they also browse English sites (and they're probably not using Firefox - its text rendering is super consistent across different systems). Safari (obviously) and Chrome (less obviously) in macOS defers to the OS for text rendering - hence the problem.
So… you think your font of choice would be better than what the user had configured as the default in their user agent?
The problem is, X and Y have different line heights and different widths. And there's no CSS / media query way to detect which font is available.
So far I'm leaning towards a very ugly solution: rendering a test string into a DIV, measuring it, and then applying the correct class to the parent element.
I thought something like this would been obvious after 2 decades of transitioning from print to web design, but I sometimes still get complaints for things like widows and orphans [0].
Given the tools to address these issues, such as Adobes proposed `text-wrap: balance`, I am sure many would do so.
Not the least of which because of text size zooming for accessibility. The web is not print!
If a font has some weird characteristic about it (for instance, the font itself has built in whitespace at the bottom or top of letters), you will not be able to center it vertically no matter what CSS magic you try to do except for doing some kind of translation on it; that translation doesn't have to be pixel-based either, but it will 100% have to happen until hopefully when the leading-trim property that saadat mentioned is widely available.
Here, try to align these without changing individual p's CSS:
https://jsfiddle.net/a3q87ucs/
You see how the second text is lower. That has to do with internal font settings that CSS has no control of. Not yet at least.
No, it doesn't. Here's the screenshot with a line I added:
https://i.imgur.com/6pLiasn.png
> if you insist on ignoring that, https://jsfiddle.net/qpb0d45n/
And now you have blocks of different heights. Which cause other issues.
[1]: https://www.w3.org/TR/css-inline-3/#leading-trim [2]: https://medium.com/microsoft-design/leading-trim-the-future-...
… My recommendation is not to implement any design that can’t handle the difference. This will be more robust and better for you in the future (e.g. i18n, zoomed fonts for a11y, etc.). Whenever I worked implementing a design by someone else and there were overly strict assumptions about text size I let them know this was a problem and suggested an alternative.
The problem with your proposed solution is that if you’re using a webfont and measure before it loads, it won’t match the width once it’s replaced. Also, back in the day browsers came with a command to increase char size instead of zooming the whole page… I no don’t know if some still do, or if it happens under certain contexts (a11y extensions?) but that would also break.
I'm not going to tell my employer I'm not implementing the design, when I can solve the problem, though in an ugly way.
> if you’re using a webfont and measure before it loads
That's not a problem. You can check if the font has loaded.
https://stackoverflow.com/questions/5680013/how-to-be-notifi...
> I'm not going to tell my employer I'm not implementing the design, when I can solve the problem, though in an ugly way.
Though you might make the site pixel-perfect on _your_ device with _your_ fonts (all the combinatorics you can think of to test), you are likely breaking something for a screen reader, or user with 200% zoom, or a braille user, or a user with hardcoded fonts for disability reasons, or a user using a Windows phone browser, or a user on IE 8, or a user viewing the site through a corporate proxy that blocks some requests, or a user with CSS styles disabled, or a user who hasn't updated his Mac in six years, or a miriad of other cases.When you're reimplementing basing browser functionality, you're breaking your site for a lot of users.
Sometimes graphic designers don't understand all the implications of their design choices in a dynamic medium. It is my job, as an experienced professional, to steer them away from the problems and do the best to capture their intention.
Almost every time designers (who many times were my employers) understood the issue when pointed out and agreed with my solution. Their designs normally only consider the "ideal" cases (e.g. every title / item description fits nicely) because they have to make it look good for the client, but they know reality requires compromise.
If you want to align the text vertically with an image, use flexbox. If the specific font they want to use doesn’t look right in that context, have them either (1) deal with it or (2) pick another font.
https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/...
I think the other advice here is a little extreme. There is no reason not to try to normalise the appearance for all users.
We have Mac users using Safari / Chrome / FF, and we have Win users using Chrome / FF / Edge.
It´s admirable to try to have look of a native platform but nobody thinks this way about websites. Plus only very small % of people would even realize difference between those sans serifs if they werent looking for it side by side.
—⁂—
But as a consumer of the web, I personally don’t actually need to worry about these things any more, because I have my browser set to use my chosen sans-serif, serif and monospace faces (Equity, Concourse, Triplicate), and you can too! ① Use Firefox. Other browsers may have something similar; dunno; but Firefox is good anyway. ② Settings (about:preferences) → Fonts → Advanced → untick “Allow pages to choose their own fonts, instead of your selections above”.
I started doing this a few months back as a week-long experiment, and found it so significantly improved the web that I’m not going back. (It did feel a little strange for a few days, as Concourse is a somewhat narrower sans-serif than the likes of Arial, but that’s about the specific fonts that I chose. Now it’s just perfectly natural.)
I have experienced a very few icon-font related breakages, about which I wrote yesterday at https://news.ycombinator.com/item?id=31540234, but it’s surprisingly few given how popular the technique was for a few years. I also get a fair bit of bonus unintended serif from people that have neglected to add a generic font family fallback, or misspelled it (e.g. sans or "sans-serif" (quoted) instead of sans-serif), so that it falls back to the global default, which I have left as a serif.
I've been doing this for several years now and I love that Firefox can do this and Chromium can't. However, as you've mentioned, icons break on several websites including DuckDuckGo and rust mdbook (the search icon is replaced as "fl"). In addition, several websites assume that their monospace web font will always load and when it doesn't, code blocks are displayed in sans-serif fonts which is a huge turn off.
I guess both of these issues happen because people assume everyone's using Chromium web browsers?
Icon fonts are pretty much an obsolete technique: they were the pragmatic choice for a few years when SVG support was insufficient (most notably for old versions of IE), but they were known* to have accessibility problems, and so now that SVG support is adequate, the icon font technique should be replaced in all cases.
For font-family declarations lacking an appropriate generic fallback family, that’s simple developer error because they don’t know how things are supposed to be done, and that all other families are unreliable—it’s not just people that deliberately disable them like us, but also that not all systems will have a font of a given name, and that web fonts may fail to load because networks are unreliable.
I could maybe forgive the use icon fonts (Google websites end up breaking the most, android's documentation website for example) but it's unforgivable to write `pre code { font-family: my-random-webfont }`.
[1]: https://kb.mozillazine.org/UserContent.css
[2]: https://superuser.com/q/318912
[3]: https://www.userchrome.org/how-create-userchrome-css.html
What do you mean? If it's wrong, the font ain't there. If the font is there, it's the correct font (according to the desire of the one who made the stack). If my stack has "Liberation Sans", it means that if your system has Liberation Sans, then it's going to be used. And it's very often better than the default system font ("Deja Vu Sans", for example, is a typical fallback on Linux and sucks big times compared to Liberation Sans and compared to many other sans-serif fonts).
The way I see it that's the entire point of these "scattershot list of guesses": you can put several, it absolutely doesn't matter. The goal is to find one that matches before falling back to the default.
The one in article is
-apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Ubuntu, roboto, noto, arial, sans-serif;
The one it actually uses is -apple-system, BlinkMacSystemFont, "avenir next", avenir, "helvetica neue", helvetica, ubuntu, roboto, noto, "segoe ui", arial, sans-serif
It looks like a minor difference, but the former one has segoe ui before helvetica (which is hard-coded as Arial alias on Windows), so it would use segoe ui on Windows; while the latter (currently using) one would show the content as Arial on Windows.How is Times New Roman, Baskerville, Garamond, and Droid Sans all in the same serif stack? These hardly look alike. Arial and Ubuntu look nothing alike. If it's not in the same lineage don't include it, go with the default.
Not really. The fonts selected by these font-family values should, at most, be dependent on the OS and language of the host system -- which are already easy to detect.
system-ui[1] deserves a mention, but OP's proposal is more thorough as it covers the Serif and Mono families.
The system font does bring some advantages though, like on macOS/iOS where that font is San Francisco, it’s designed specifically to look good and read well on screen. Under WebKit you even get hand-tweaked letterforms, metrics, and kerning for different combos of size, weight, and context (title, subtitle, body, etc).
Something that would be really cool is if all browsers did what Apple is doing with San Francisco by shipping with a FOSS screen-oriented font like Inter UI[0].
Preferences > General > Fonts > Advanced…
[ ] Allow pages to choose their own fonts, instead of your selections above
This may cause issues with icon fonts.Should we restrict every digital text to Times New Roman only?
* I cannot, in good conscience, say that image support was a mistake. There is too much valuable work that cannot be expressed well in text and needs to be graphical. Ditto sound and video.
* Once you’ve added images, you need rich text. If it’s not there, people who insist on doing it anyway will fake it using pictures of text, which is simpler than proper rich text support, but also a lot worse because it doesn’t work with TTS, cannot be indexed for search, and doesn’t work with the clipboard.
The “pictures of text” problem is not just professional designers justifying their paychecks. They’re all over the place on Twitter and Facebook, because of the poor text formatting options they provide.
The web had rich text even before it had images, in the form of emphasis and strong emphasis, as well as a variety of other forms of semantic markup to indicate document structure and relationships.
What I’m saying is that if a web page doesn’t work on NCSA Mosaic from 1994—modulo modern crypto and character sets—it is doing something very wrong.
I don’t care that this represents a large proportion of the web today, that doesn’t make it any less wrong.
Just because you can pound nails with a screwdriver doesn’t mean we should just start catering to people who want to do that. Or people who want to use knives as screwdrivers. Etc.
You may as well be saying why even have different typefaces on computers at all.
REALITY: The engineers who would eventually build all this just laugh and don't care. And HN will talk about this again next year.
Therefore I would prefer that every major browser (Safari, Chrome and Firefox) ships its own reasonably chosen set of fonts and doesn't access system fonts (however the user may grant access to system fonts if they are fine with fingerprinting).
This could also simplify web design because now there will be a somewhat standartized set of fonts.
And more info here: https://web.dev/local-fonts/
Of course, browser should use its own font rendering library instead of using a system one.
Of course, for browsers that target a single platform (like Safari which is available only on MacOs) this is not an issue, but Chrome or Firefox might be used on many platforms, like Windows 8, Windows 10, Windows 11, Debian, Ubuntu, FreeBSD, Plan 9, Chrome OS and so on.
The pref names and their possible values:
# Visibility level of font families available to CSS font-matching:
# 1 - only base system fonts
# 2 - also fonts from optional language packs
# 3 - also user-installed fonts
layout.css.font-visibility.standard
layout.css.font-visibility.trackingprotection
layout.css.font-visibility.resistFingerprinting
https://searchfox.org/mozilla-central/rev/de15f9c109f9c474d0...Here's the Firefox bug about enabling these prefs, probably in Tracking Protection Strict mode to start: https://bugzilla.mozilla.org/show_bug.cgi?id=1736005
Switched all settings to 1.
That’s not true. Emojis are Unicode characters just like `a` or `ß`. When I type <an emoji character> on my computer it doesn’t magically change font in the middle of the sentence; it’s just a character.
edit: looks like HN stripped away my emoji.
Emoji are often rendered using the system's font fallback mechanism. When one font doesn't have the glyph required, another font that does have the glyph gets picked. Most fonts don't have glyphs for non-western scripts; there are only a few fonts out there that cover most of the Unicode standard, often made up of several fonts combined.
You're not manually changing the font-face mid sentence, but when you use emoji the renderer is definitely switching fonts to one you didn't specify.
It's not magic but it can happen. In fact, it usually does. Helvetica doesn't have emoji glyphs. Guess what happens if you drop an emoji in a block of text formatted with Helvetica?
browser vendors should just include Inter and make it the default web font
And while I wonder that, I thought of a weird alias.. firefox-system or chrome-system would be terrible.
https://caniuse.com/font-family-system-ui https://infinnie.github.io/blog/2017/systemui.html
All fonts should clearly distinguish between a capital I and lower-case L.
If you don’t care about having the same font on all devices, what’s the point of this:
> font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Ubuntu, roboto, noto, arial, sans-serif;
versus that:
> font-family: sans-serif;
?
Sans-serif will get you ugly fonts, such as Arial on Windows, and likely DejaVu Sans or Liberation Sans on Linux.
Chrome: https://i.imgur.com/fFnX6hu.png
Firefox: https://i.imgur.com/HDfbeYh.png
You can't do anything (other than using Stylish/Stylus, I suppose) if the dev hardcoded the font-family.
In a perfect world the defaults would look great, making sans-serif a viable choice and allowing the few users who really care (beyond 'it looks good') to do whatever they want.
Well, i just disable "Allow pages to choose their own fonts, instead of your selections above" in browser font selection dialog.
Exactly. I find Liberation Sans very good but I cannot stand DejaVu Sans (which is the sans serif font all too often when browsing sites from Linux).
Also, Arial is not ugly. It looks good on print.