DEV Community

ente
ente

Posted on • Originally published at ente.io

3 2

system-ui and friends

The CSS one-liner to use system fonts

We love our custom fonts, but they come with a cost that we don't often realize.

When we load a font over the internet, be it from our own website or (god forbid) Google Fonts, there is a small but perceptible "layout flash" for our visitors. This happens because the browser initially renders the content using the fallback font, then re-renders it after the custom font has been downloaded over the network.

Worse, this is something that happens only once (generally).

"Why is that worse?", you'd ask.

Well, it's worse because after the first load the font gets cached on the developer's machine, and then they become oblivious to the problem. They don't see the website the way a first-time visitor would see it. They feel confident about their code's performance, while the first-time visitor to the website walks away with an amateurish first impression as they see the website loading first, then everything shifting around and getting re-rendered again.

Now, this is not a niche problem, and there are many approaches that developers have used to improve the user experience. But these come with complexity.

The simplest solution is to let go of the custom font, and to just use the system font! (Thank you, Captain Obvious).

The issue with this is that there isn't a browser standard way to use the default, OS sans serif font. Or rather, there wasn't such a way previously.

Now there is, with font-family: system-ui, the hero of our post.

Cool. Are we done?

Well, as you'd have guessed, browser support for this is still in the works. So in the meanwhile, we need to use this longer version that provides fallbacks for most OSes.


font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Ubuntu, Arial, sans-serif;

Enter fullscreen mode Exit fullscreen mode

Using the system font is not always a solution, but for where it is (for example, in the body of transactional HTML emails), it is often a better approach than loading a custom font.

Till next time, happy CSSing! 🧑‍💻


If you'd like to hear more about our battles with browsers, follow us on Twitter.

Or if you'd hang out with a bunch of engineers building an e2ee photo storage service, come say hello on Discord.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay