I am trying to add custom fonts in magento 2 transactional emails however, it does not work. I am using hyva theme.
I have imported Sofia-pro font under app/design/frontend///web/fonts/SofiaProRegular.woff2 and app/design/frontend///web/fonts/Sofia_pro_regular.ttf
Then I have added _typography.less file under app/design/frontend///web/css/source/_typography.less and added the following code in it
.lib-font-face {
@family-name: @font-family-name__base;
@font-path: '@{baseDir}fonts/SofiaProRegular.woff2';
font-weight: 300;
font-style: normal;
}
After that, I added the following code inside _variable.less
@font-family-name__base:'Sofia-pro';
@font-family__base: @font-family-name__base, @font-family__sans-serif;
Then tried using in my less file as,
body {
font-family: 'Sofia-pro', Sans-serif';
}
But, none of that seems to work, the font is not applied into my email template.
How do I apply custom fonts in my transactional email templates in magento 2?
My magento 2 version is magento 2.4
Best Answer
You need
SofiaProRegular.woff
andSofiaProRegular.woff2
for fonts files. Your font path in your code is incorrect, this patch shouldn't use the file extension.To achieve your goal, take the following step:
Add font files to your local theme directory. For example,
app/design/frontend/<your_vendor_name>/<your_theme_name>/web/fonts
.Create
app/design/frontend/<your_vendor_name>/<your_theme_name>/web/css/source/_typography.less
fileapp/design/frontend/<your_vendor_name>/<your_theme_name>/web/css/source/_email.less
fileYou're done.
Related document: