@import and <link> techniques aren’t supported).
In this tutorial, you’ll learn how to add your own custom fonts to emails in Maizzle.
Initial setup
First, let’s scaffold a new project:./example-font-face, and select the Default Starter.
Choose Yes when prompted to Install dependencies.
Once it finishes installing dependencies, open the project folder in your favorite editor.
Register @font-face
Imagine we have a display font called Barosan, which we’re hosting on our website. We’ll use@font-face to register our custom font family - we can do this in the Template or in the Layout that we extend.
Add in Template
Openemails/transactional.html and add this before the <x-main> tag:
emails/transactional.html
<style> tag in the compiled email HTML, right after the main one.
Add in Layout
If you prefer a single<style> tag in your email template, you can register the font in the Layout instead. Open layouts/main.html and update the <style> tag:
layouts/main.html
You can use the same technique to load font files from Google Fonts - it’s currently the only way to get them working in Shopify notifications. To find out the URL of a Google Font (and actually, its entire
@font-face CSS) simply access the URL they give you, in a new browser tab.Tailwind CSS utility
Now that we’re importing the font, we should register a Tailwind CSS utility for it. Opentailwind.config.js, scroll down to fontFamily, and add a new font:
tailwind.config.js
cursive.
Great! We’re now ready to use the utility class in our email template.
Quick use
Add thefont-barosan class on elements that you want to use your custom font.
For example, you can add it on a heading:
Advanced use
Repeatedly writing thatfont-barosan class on all elements isn’t just impractical, it also increases HTML file size (especially when inlining), which then leads to Gmail clipping.
font-family is inherited, which means you can just add the utility to the top element:
emails/transactional.html
screen variants and an Outlook font-family fallback to reduce bloat and write less code.
First, let’s register a new @media query - we will call it screen:
tailwind.config.js
emails/transactional.html
Don’t add it to the
<body> - some email clients remove or replace this tag.font-family away in an @media query:
@media queries, define a fallback for it in the <head> of your Layout:
layouts/main.html
The Maizzle Starter includes this fallback in the
main.html Layout by default.Outlook bugs
Custom fonts aren’t supported in Outlook 2007-2019 on Windows - most of these email clients will fallback to Times New Roman if you try to use one. To avoid this, you can wrap the@font-face declaration in a @media query, so that Outlook will ignore it:
font-family isn’t inherited on child elements in Outlook.
Extra weights
If your font comes with dedicated files for other weights, don’t just slapfont-bold on an element.
Instead, import both the regular and bold versions of your font: