Layout
Using the same Google Fonts in all your emails? Paste the code in your main Layout. For example, add it before Tailwind CSS:layouts/main.html
Template
If you only need Google Fonts in a certain Template, push to thehead stack:
emails/example.html
<stack name="head" /> in main.html - that’s where Google Fonts will be output!
Notice the
media="screen" attribute on the last <link> tag - that helps avoid the Times New Roman fallback font bug in older versions of Outlook.Tailwind CSS utility
After pasting in the code from Google Fonts, you have one more thing to do: register thefontFamily utilities in your tailwind.config.js, so you can use classes generated by Tailwind.
For example, let’s register a Tailwind utility for Open Sans:
tailwind.config.js
font-open-sans and font-merriweather utility classes.
Avoid inlining
Although having the font-family CSS inlined on the first element in your HTML should be enough, there might be situations where that isn’t desirable. Email clients that support web fonts don’t actually require thefont-family CSS to be inlined in your HTML. Therefore, we can make use of Tailwind’s breakpoints and tuck the class inside an @media screen {} query.
This way it doesn’t get inlined and you can keep this CSS away from any email client that doesn’t support @media queries.
To do this, we first register a screen breakpoint:
tailwind.config.js
emails/example.html
@font-face
Some email clients or ESPs don’t support<link> tags or CSS import(), but do support web fonts. In such cases, you can use @font-face and add your Google Fonts right inside your <style> tag.
First, visit the URL that Google Fonts creates for you after you’ve selected your fonts.
In our example, it’s the following:
@font-face declarations in there, for example:
@font-face declarations that you need and add them either in a Template or in the Layout your templates extend (for global usage) - see our web fonts in HTML emails guide to learn how to do so.
Note that you’ll still need to register the Tailwind CSS utility in order to use the fonts.