I've included a custom font on my website (Segoe UI
), however the font file are around 1mb, which takes a few seconds to load the first time.
I'm on a Mac, and the font is not shipped with OSX. However, as far as my knowledge goes, it's included with Windows.
How can I make CSS only load the font if it's not already existing on the client?
Add a font-face section to your CSS code src: url('fonts/lovely_font. otf') format('opentype'); src: url('fonts/lovely_font. ttf') format('truetype'); As another optional efficiency measure, we can get the browser to check for a local copy of the font in case the user already has it.
The only way to ensure a non-standard font is displayed correctly is to embed the font into the . css (see Non-Standard Fonts below). The table below lists fonts that are standard to Windows and Mac systems along with the fallback font-family name used for other devices.
Using local('Segoe UI')
worked out. Seems like it prioritizes the sources from first to last.
Here's the working code
@font-face {
font-family: Segoe;
src: local('Segoe UI'), url('fonts/segoeui.ttf') format('truetype'), url('fonts/segoeui.woff') format('woff');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With