How do I use .woff fonts for my website?
To use .woff
fonts in your site, you only need to define a CSS @font-face
rule, as shown below:
Make sure your replace 'YourFont'
with your custom font name, and 'fonts/YourFont.woff2'
as well as 'fonts/YourFont.woff'
with your font paths. This process loads the .woff
font, while using fallback default system fonts in situations where the custom font cannot load.
Custom font checklist: Dos and Don'ts
Always consider browser compatibility and the performance implications of using custom fonts. Do your homework on how your font fares across different browsers and operating systems.
For an optimal performance, prioritize the .woff2
format as it has better compression capabilities, which effectively means faster load times. Side note: No, .woff2
is not a sequel to .woff
, it's an improvement.
Also remember, proper font loading techniques such as font loading APIs or the CSS font-display
property can help avoid the flash of unstyled text (FOUT) or flash of invisible text (FOIT).
Storing fonts: All in one place
Organizing your custom fonts
Place your custom font files in a structured directory, typically a fonts
subfolder, to keep your workspace tidy.
Serving fonts efficiently
To decrease site loading times, make sure you enable HTTP compression in your server setup for .woff
and .woff2
files and that browser caching is optimized to reduce repeat downloads for recurring visitors.
Browser support: Not all are alike
Firefox compatibility
Firefox users deserve the best too. To ensure Firefox compatibility, make sure your server has the correct MIME types configured for serving .woff
and .woff2
formats. Put simply, Firefox needs this information to understand the file type it's dealing with.
Supporting older browsers
Offer a fallback for older browsers (Yes, there are people still using old browsers. Some even think the world is flat.) that do not support our hero .woff
by including an alternative font format, such as Embedded OpenType (.eot
).
Simple steps: Visualizing font usage
Just like baking a cake! Your ingredients are ready, let's move on to baking.
Upgrading your font usage
Implementing uniqueness
Do you want your text to have a beard? You can make it bold. Want to tilt it a bit? Make it italic. By using distinct @font-face
rules for each font style and weight, you can easily manage each variant.
Using local fonts
Why download a font file if it's already there? If some users might already have your font installed locally, you can use the local()
function. But proceed with caution! Sometimes, the local versions might differ from your intended font.
Applying and enhancing your custom fonts
Tailoring your typography
Apply your font to specific elements or to the body
or html
tag for a generic solution, giving a consistent look across your website.
Planning for the worst
Always, and I mean always, define a fallback font. In situations where your first-choice custom font fails to load, you'll thank yourself for having a plan B.
Was this article helpful?