Learn how to add rounded corners, drop shadows, and custom Google fonts in your HTML emails. This tutorial covers the concept of progressive enhancement and provides a step-by-step guide on how to enhance the design of your emails using CSS.
Key Insights
- The tutorial teaches you how to add rounded corners to images using CSS border-radius. If not supported by the email client, the images will retain their square corners.
- You can add a drop shadow to your images with the box-shadow property in CSS. The tutorial provides a guide on how to apply this to the three date listing images.
- The tutorial includes a guide on how to implement a custom font from Google Fonts, a popular source of free web fonts.
- While adding custom web fonts, it is essential to test the fallback font as custom fonts are not supported everywhere.
- For email clients like the Windows versions of Outlook that do not understand custom web fonts, a conditional style specific to the email client can be included.
- The tutorial also provides an exercise which involves working with prepared files in the code editor and progressively enhancing a date listing image.
Dive into this detailed tutorial on enhancing HTML emails with rounded image corners, box shadows, and custom fonts from Google Fonts.
This exercise is excerpted from Noble Desktop’s HTML Email training materials and is compatible with updates through 2021. To continue learning HTML Email with hands-on training, check out our coding bootcamps in NYC and live online.
Topics Covered in This HTML Email Tutorial:
Rounding Image Corners with Border Radius, Adding CSS Box Shadow, Custom Web Fonts: Adding Google Fonts
Exercise Preview
Exercise Overview
In this exercise, you’ll add rounded corners and drop shadows to the 3 date listing images. You’ll also add a custom font from Google Fonts. These may not work everywhere, but will in some email clients. This approach is called progressive enhancement and lets some people benefit, while others (who don’t see the extras) will still receive a nicely styled email.
Getting Started
Open your code editor if it isn’t already open.
We’ll be switching to a new folder of prepared files for this exercise. Close all open files in your code editor to avoid confusion.
For this exercise we’ll be working with the Date Night Progressive Enhancement folder located in Desktop > Class Files > yourname-Responsive HTML Email Class. You may want to open that folder in your code editor if it allows you to.
Open date-night-exclusive-picks.html from the Date Night Progressive Enhancement folder.
Implementing Border-Radius on the Images
Let’s upgrade our design by adding rounded corners to each of the 3 date listing images. This is done with CSS border-radius, which some email clients support. In those that don’t, the corners will remain square.
-
Let’s find how to target the images with CSS. Scroll to the image of the Couple Fighting (around line 140) and notice it’s in a td with a class of deviceWidth:
<td class="deviceWidth" align="left" width="50%" valign="top" style="padding-right: 10px;"> <a href="https://www.example.com" target="_blank"><img class="resImage" src="http://www.nobledesktop.com/nl-date-night/img/couple-boxing@2x.jpg" width="290" ALT="Couple Fighting"></a> </td>
-
Scroll up to the top of the CSS styles. Below the img rule, add this new rule:
.deviceWidth img { border-radius: 20px 0; }
Save the file.
-
Preview date-night-exclusive-picks.html in a browser. We’ll keep reloading this file, so leave it open.
Sweet, all three date listing images have top left and bottom right corners that start rounding off when they are 20 pixels away from the images’ borders!
Resize the browser window to see how it looks in all layouts.
Adding Box-Shadows
We also want to add a drop shadow to the date listing images.
-
Return to your code editor and add box-shadow as shown below in bold:
.deviceWidth img { border-radius: 20px 0; box-shadow: 0 4px 8px #888888; }
This property takes 4 parameters in this order: horizontal offset (0px), vertical offset (4px), blur (8px), and color (#888888).
Save the file and reload the browser. Awesome—we have a nice, soft, subtle drop shadow behind each of the 3 date listing images!
Custom Web Fonts: Adding Google Fonts
Let’s see how to add a custom web font. Keep in mind these custom fonts are not supported everywhere, so you’ll want to make sure you test the fallback font which some people will see! Let’s see how to use custom web fonts from Google Fonts, a popular source of free web fonts.
- In a new browser tab, go to fonts.Google.com
- In the search field, type in the font we want to add: Bree Serif
- In the search results, click on Bree Serif.
- Click + Select this style to the right of the Regular 400 weight.
- As side panel should appear. At the top right of that, click on the Embed tab.
-
Copy the link to the Google-hosted style sheet:
<link href="https://fonts.googleapis.com/css2?family=bree+serif&display=swap" rel="stylesheet">
-
Return to your code editor and paste it around line 6, below the title tag and above the style tag, as shown in bold below:
<title>Date Night Exclusive Picks</title> <link href="https://fonts.googleapis.com/css2?family=bree+serif&display=swap" rel="stylesheet"> <style>
-
In the font-family for h1 and h2 (around lines 22 and 29), add the name of the custrom font as the first choice, before the sans-serif fallback font (which will be used if the custom font does not work), as shown below in bold:
h1 { color: #69655c; font-family: 'Bree Serif', sans-serif;
Code Omitted To Save Space
} h2 { color: #696969; font-family: 'Bree Serif', sans-serif;
Code Omitted To Save Space
}
Save the file and reload date-night-exclusive-picks.html in the browser. The headings and subheadings should all have the custom font!
Web Fonts in Outlook
Some Windows versions of Outlook (2007,2010 and 2013) do not understand custom web fonts. They will default to Times New Roman, even if a sans-serif fallback is defined in our font stack.
In this email, Times New Roman looks fine. But if you were using a sans-serif font, you would need to include a conditional style specific to desktop Outlook, telling it to display a web safe font.
For example, at the top of your styles you would need to add:
<!—[if mso ]>
<style type="text/css">
h1, h2 {
font-family: sans-serif;
}
</style>
<![endif]—>