Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use @font-face in an email?

Here's a tricky question about CSS. I have to send an email with some styles. The only way to make styles work in the email is writing them just after the tags (I cannot even write a <style type="text/css"> because mail server ignores it). So, this is an example of what I have to do:

<div style="background: red;"></div>

For instance, that works perfect. The problem is I need to use the css @font-face query. Is there any way to include it like this?

<div style="background: red; @font-face { font-family: 'myFont'; src: url('myURL'); }"></div>

Note: obviously last line is not working at all.

Here is a similar post with an answer:

Can @fontface be used within a tag? (for email signature reliability)

But I cannot use an external style sheet or copy it in a style section, because it will not work.

Thank you in advance.

like image 392
forvas Avatar asked Feb 28 '14 13:02

forvas


People also ask

Does font face work in email?

You can! But with all things cool in html-email it will not work in every client/browser. @font-face will work in iOS and (most of) Android's default clients, Apple Mail, and Outlook 2011 for Mac. Everything else either strips your whole <style> tag or just ignores it.

How do I use font face?

With the @font-face rule, web designers do not have to use one of the "web-safe" fonts anymore. In the @font-face rule you must first define a name for the font (e.g. myFirstFont), and then point to the font file.


1 Answers

Take a look at this. After much testing it is the best supported technique I came up with for webfonts.

If you want it only for a signature, say out of Outlook - There is no technique I'm aware of. Even though you can call it inline, all the techniques to actually add/call the webfont URL need to be in a <style> tag. It is like trying to call an external style sheet inline... Don't think it is possible.

Also, in html email, you need to use the 6-digit hex code when declaring colors. Try background-color:#FF0000;

like image 128
John Avatar answered Sep 19 '22 05:09

John