惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google Online Security Blog
Google Online Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The GitHub Blog
The GitHub Blog
S
Secure Thoughts
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
WordPress大学
WordPress大学
SecWiki News
SecWiki News
B
Blog
小众软件
小众软件
Hacker News - Newest:
Hacker News - Newest: "LLM"
Webroot Blog
Webroot Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
L
LINUX DO - 热门话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
Know Your Adversary
Know Your Adversary
Y
Y Combinator Blog
F
Fortinet All Blogs
W
WeLiveSecurity
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI
The Last Watchdog
The Last Watchdog
S
Schneier on Security
爱范儿
爱范儿
V
V2EX - 技术
L
LINUX DO - 最新话题
月光博客
月光博客
博客园 - 【当耐特】
Latest news
Latest news
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
U
Unit 42
Schneier on Security
Schneier on Security
E
Exploit-DB.com RSS Feed
J
Java Code Geeks
Cyberwarzone
Cyberwarzone
T
The Blog of Author Tim Ferriss
TaoSecurity Blog
TaoSecurity Blog
博客园 - 叶小钗
T
Troy Hunt's Blog
大猫的无限游戏
大猫的无限游戏
AI
AI
Security Latest
Security Latest

Matthias Ott

Hello Again, World This, Still Not for Everyone The Shape of Friction WeissKlang L1 – Punching Above Its Weight Continvoucly Morged Value Webspace Invaders To Affinity and Beyond The Mystery of Storytelling Amateurs! Echoes of Connection Linear() Is Not (That) Linear View Transitions: The Smooth Parts Adding AVIF and WebP Support to My Craft CMS Site Challenge Acoustic Room Treatment and Building Sound Panels, Part 1: Planning Play On Overshoot The HTML Output Element Listening Closely Compressed Fluid Typography The Lifeblood of the Web What Could Go Wrong? That’s My Rank Making Space CSS :is() :where() the Magic Happens Visual Regression Testing for External URLs With Playwright Jane Goodall’s Famous Last Words European Tech Alternatives 🇪🇺 Independent Type Foundry Advent Calendar – Day 24: NaN Independent Type Foundry Advent Calendar – Day 23: Typotheque Independent Type Foundry Advent Calendar – Day 22: 205TF Independent Type Foundry Advent Calendar – Day 21: HvD Fonts Independent Type Foundry Advent Calendar – Day 20: Frere-Jones Type Independent Type Foundry Advent Calendar – Day 19: Fontwerk Independent Type Foundry Advent Calendar – Day 18: Vectro Independent Type Foundry Advent Calendar – Day 17: Studio René Bieder Independent Type Foundry Advent Calendar – Day 16: R-Typography Independent Type Foundry Advent Calendar – Day 15: David Jonathan Ross Independent Type Foundry Advent Calendar – Day 14: Interval Type Independent Type Foundry Advent Calendar – Day 13: Newglyph Independent Type Foundry Advent Calendar – Day 12: Swiss Typefaces Independent Type Foundry Advent Calendar – Day 11: Sharp Type Independent Type Foundry Advent Calendar – Day 10: Colophon Foundry Independent Type Foundry Advent Calendar – Day 9: Commercial Type Independent Type Foundry Advent Calendar – Day 8: Letters from Sweden Independent Type Foundry Advent Calendar – Day 7: Lineto Independent Type Foundry Advent Calendar – Day 6: Ohno Type Company Independent Type Foundry Advent Calendar – Day 5: Milieu Grotesque Independent Type Foundry Advent Calendar – Day 4: TypeMates Independent Type Foundry Advent Calendar – Day 3: Klim Type Foundry Independent Type Foundry Advent Calendar – Day 2: Dinamo Independent Type Foundry Advent Calendar – Day 1: Grilli Type The Independent Type Foundry Advent Calendar 2022 A Conversation With ChatGPT ChatGPT, please explain websites in the words of William Shakespeare Transient Frameworks Leaving Twitter Behind Converting Your Twitter Archive to Markdown The Wrong Question It Wasn’t Written Syndicating Posts from Your Personal Website to Twitter and Mastodon Suspension None of Your Business Doing Our Part Patch That Package Brain Dump Generating Accessibility Test Results for a Whole Website With Evaluatory The CSS Cascade, a Deep Dive Updates About Updates How to Delete Your Commit History in Git Unblocking Your Writing Blocks, Part 2: I’m Not an Expert nor a “Thought Leader” Connections No Wrong Notes Better Options Design Debt Finite and Infinite Games Don’t Assume, Validate. Necessity Is the Ultimate Teacher One Egg Go Deep There Is No Secret Code Balancing Risk Blue Eyes, Brown Eyes The Shortcut Boomerang My RSS Feed Collection of Personal Websites Frequency The Illusion of Control The Decisions Journey Write It Down Nownownow Into the Personal-Website-Verse Considering the Opposite What is it for? Unlimited Bowling. Never done. We Are Team Internet. We Need to Save #NetNeutrality. Progressive Search Data loss (also) by JavaScript Books I Will Definitely Maybe Read in 2017 Starting to Write Notes
The Right Way to Use fonts.com Web Fonts
Matthias Ott · 2020-06-02 · via Matthias Ott

Let’s talk about web fonts. More specifically, about a mistake I have seen developers make in several projects for different agencies: Embedding a web font in the wrong way. In each of the cases, the service they were using was Fonts.com, and given the service’s popularity, this quick tip might come in handy for some people.

So what’s the problem? When you download a font for self-hosting, it often comes with some demo CSS, so that you see how you can use the web font in your project. Fonts.com does that, too. Here is how that CSS code looks like, for example:

/* CSS / Sass */
@font-face {
  font-family: "DIN Next LT W01 Regular";
  src: url("Fonts/936930ba-a8da-4765-9e89-0f35cdff223f.eot?#iefix");
  src: url("Fonts/936930ba-a8da-4765-9e89-0f35cdff223f.eot?#iefix")
      format("eot"),
    url("Fonts/6b4d4830-9c7d-43d2-b5d3-c73f739561b9.woff2") format("woff2"),
    url("Fonts/ccf25ada-6d2a-4133-95dc-deb039e22999.woff") format("woff"),
    url("Fonts/126195b4-2fa0-4b95-b5cf-ad9bf10193f0.ttf") format("truetype"),
    url("Fonts/58fc798b-98f9-4485-8d2b-7b93a71ee2a6.svg#58fc798b-98f9-4485-8d2b-7b93a71ee2a6") format("svg");;
}

@font-face {
  font-family: "DIN Next LT W01 Bold";
  src: url("Fonts/fa5ed46b-792d-4f47-894e-fa587cf4e1cf.eot?#iefix");
  src: url("Fonts/fa5ed46b-792d-4f47-894e-fa587cf4e1cf.eot?#iefix")
      format("eot"),
    url("Fonts/03008527-67bd-478e-98e3-3b56dd9a6520.woff2") format("woff2"),
    url("Fonts/557f817d-9c25-4a23-baaf-a3cf84a7cd7c.woff") format("woff"),
    url("Fonts/92ed1479-1d40-4a94-8baf-6abd88b17afa.ttf") format("truetype"),
    url("Fonts/03008527-67bd-4485-8d2b-7b93a71ee2a6.svg#03008527-67bd-4485-8d2b-7b93a71ee2a6") format("svg");;
}

First of all, you might not need the older file formats EOT, SVG, and even TTF. Modern browsers all understand WOFF of WOFF2, so let’s get rid of the rest.

/* CSS / Sass */
@font-face {
  font-family: "DIN Next LT W01 Regular";
  src: url("Fonts/6b4d4830-9c7d-43d2-b5d3-c73f739561b9.woff2") format("woff2"),
    url("Fonts/ccf25ada-6d2a-4133-95dc-deb039e22999.woff") format("woff");
}

@font-face {
  font-family: "DIN Next LT W01 Bold";
  src: url("Fonts/03008527-67bd-478e-98e3-3b56dd9a6520.woff2") format("woff2"),
    url("Fonts/557f817d-9c25-4a23-baaf-a3cf84a7cd7c.woff") format("woff");
}

Much better already. Also make sure that WOFF2 comes before WOFF so that browsers which support the 30 % smaller WOFF2 format will use it.

But back to the initial problem. When you wanted to use the fonts defined in the code above, you would reference the font-family from the @font-face rule like so:

/* CSS / Sass */
p {
	font-family: "DIN Next LT W01 Regular", sans-serif;
}

strong {
	font-family: "DIN Next LT W01 Bold", sans-serif;
}

Can you see the problem? No? There are actually two problems this creates. The first one is that by only using a separate font-family for each font-weight, you are creating faux-bold text. In the example above, the browser will artificially add an extra bit of “boldness” to all text that is marked up with strong. That’s clearly not what we want, so I have seen people simply adding a font-weight rule to their code:

/* CSS / Sass */
p {
	font-family: "DIN Next LT W01 Regular", sans-serif;
	font-weight: normal;
}

strong {
	font-family: "DIN Next LT W01 Bold", sans-serif;
	font-weight: normal;
}

Problem solved! Well, no, not really. Now our strong text will be rendered with the bold font without any additional weight – but only if the web font successfully loads. When the download fails (or a user uses a content blocker to block web fonts from loading) our strong text suddenly isn’t bold at all. It is as normal-looking as the rest of the text.

And there’s another problem. Sometimes, people don’t even bother to use the right font-family for elements that should have bold text or are rendered in bold via the browsers default styles.

/* CSS / Sass */
body {
	font-family: "DIN Next LT W01 Regular", sans-serif;
	font-weight: normal;
}

strong {
	font-weight: bold;
}

It might not be immediately visible to the untrained eye, but any seasoned designer or typographer will see the difference. Strong is now faux-bold again. Because the regular weight is used for the whole body, the strong element will get the bold font of the family. But in this case, the family is "DIN Next LT W01 Regular" and a bold font does not exist. So the browser will faux-bolden the text. Not only does this change the contrast and letterforms of the typeface and thus look clunky and unprofessional, it even can create this:

Futura rendered in the Book weight, as well as in faux bold.

Paul Renner’s Futura is a font with sharp edges. Different browsers will give their best to artificially make the font bolder. But you will end up with distorted proportions and shapes.

There is one simple solution to all of those problems: Properly define a font-family with different font-weights and font-styles in your @font-face declarations. Instead of using a font-family for each font, use the same family name for all fonts and tell the browser which weight (and style) it is:

/* CSS / Sass */
@font-face {
  font-family: "DIN Next LT W01";
  src: url("Fonts/6b4d4830-9c7d-43d2-b5d3-c73f739561b9.woff2") format("woff2"),
    url("Fonts/ccf25ada-6d2a-4133-95dc-deb039e22999.woff") format("woff");
    font-weight: 400;
    font-style: normal;
}

@font-face {
  font-family: "DIN Next LT W01";
  src: url("Fonts/03008527-67bd-478e-98e3-3b56dd9a6520.woff2") format("woff2"),
    url("Fonts/557f817d-9c25-4a23-baaf-a3cf84a7cd7c.woff") format("woff");
    font-weight: 700;
    font-style: normal;
}

And that’s it! Now, your strong text – or also your headlines, if you like – will use the bold font-weight and also have the correct fallback font in case the web font doesn’t load. The same goes for italic or cursive fonts.

Unless you are using a JavaScript-based web font loading strategy, you might also add font-display: swap to the code. By that you opt-in to so-called FOUT (Flash of Unstyled Text) on browsers with support for font-display. So while the site loads, the fallback font is shown first, and as soon as the web font has been downloaded, the fallback font is swapped with the new one.

/* CSS / Sass */
@font-face {
  font-family: "DIN Next LT W01";
  src: url("Fonts/6b4d4830-9c7d-43d2-b5d3-c73f739561b9.woff2") format("woff2"),
    url("Fonts/ccf25ada-6d2a-4133-95dc-deb039e22999.woff") format("woff");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
  font-family: "DIN Next LT W01";
  src: url("Fonts/03008527-67bd-478e-98e3-3b56dd9a6520.woff2") format("woff2"),
    url("Fonts/557f817d-9c25-4a23-baaf-a3cf84a7cd7c.woff") format("woff");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

Done.

Final remark: There might be one situation in which using faux-bold text might actually be useful and justified. If you are using a two-stage font loading strategy as Zach Leatherman did for CSS-Tricks. It basically means that you are splitting your web fonts into a smaller chunk and a larger lazy-loaded chunk, for example by loading the regular version of the font first and showing the faux-bold text to your users until the real bold font-weight arrives. By that, you can mitigate text movement across the page a bit as soon as your web fonts are loaded and the text reflows.

This is the sixth post of my 100 days of writing series. You can find a list of all posts here.

~