Learn the intricacies of HTML emails including adding invisible images or 'shims' and assigning alt text. Perfect these skills to enhance your potential career in front end development or digital marketing.
Key Insights
- The tutorial covers important topics such as adding an invisible shim image and assigning alt text to a shim.
- A shim image or spacer is a 1x1 pixel gif, often used to hold alt text for a background image which ordinarily cannot be assigned alt text.
- The tutorial provides an exercise where users can practice adding a shim image to an HTML email, and assigning it alt text.
- Users are also guided on how to make changes to the appearance of the image, including making it invisible in certain views or making the alt text appear in mobile view.
- The tutorial emphasizes the importance of alt text in enhancing the usability of emails for mobile users, especially if images do not load.
- Despite the process being complex and requiring precision, the tutorial provides a step-by-step guide to ensure learners can effectively understand and apply these techniques in their work.
Learn how to add an invisible shim image and assign ALT text to a shim through a comprehensive HTML Email tutorial, exploring techniques for creating a mobile-friendly email interface.
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:
Adding an Invisible Shim Image, Assigning ALT Text to a Shim
Exercise Preview
Exercise Overview
In this exercise you will take a closer look at the mobile banner. Unlike regular images in an email, background images cannot be assigned ALT text. If a mobile email client does not load images, the reader wouldn’t know what the banner is for.
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.
Open date-night-exclusive-picks.html from the Desktop > Class Files > yourname-Responsive HTML Email Class folder.
Adding an Invisible Image
In order to assign ALT text to the background image, we will add a small transparent.gif inside the table cell.
- Preview date-night-exclusive-picks.html in Chrome.
- Let’s disable images to see what the email looks like if users do not load images. We can do that Chrome’s settings. Keep this page open, and create a new tab in Chrome.
- At the top right of Chrome’s window click the Settings button
and from the menu choose Settings.
- At the top, in the Search settings field type in image
- Click on Site Settings.
- Click on Images.
- Click the toggle button to the right of Show all (recommended).
- Keep this tab open, but switch back to the tab for your email.
- Reload the page and all the images should disappear.
- Resize the browser window smaller to trigger the media query, showing the mobile phone style (you’ll have to open the DevTools to get the viewable area small enough).
Note how there is no ALT text for the banner.
- Return to your code editor.
Scroll down to the mobileBanner table cell (around line 128), noting the header.png image. We are going to add a tiny, invisible image that will hold our ALT text.
-
Directly before the header image, add the following code in bold:
<td class="mobileBanner" align="center" width="100%"> <p class="preheader">Punch-drunk in love? Go boxing with your sweetheart. This and more great dates inside!</p> <a href="https://www.example.com" target="_blank"><img src="http://www.nobledesktop.com/nl-date-night/img/shim.gif" width="1" height="1" ALT="Date Night Mobile" align="center" class="shim"><img class="resImage" src="http://www.nobledesktop.com/nl-date-night/img/header.png" width="680" ALT="Date Night"></a>
NOTE: A 1x1 pixel gif is often called a shim or spacer. While popular in the early days of HTML email, they have fallen out of favor and are not recommended as a best practice. Here, it is necessary to get the ALT text we’re looking for.
Notice that the ALT description is on the shim. By applying the text we want here, we’ll create the appearance of having an ALT description on the background image.
Let’s create some style rules for this new image. Though it’s nearly invisible, we would prefer to hide the shim.gif when possible.
-
At the bottom of the general styles, around line 59, add the following rule as shown in bold below:
img.shim { display: none; }
Making the ALT Text Appear in Mobile View
-
Scroll down to max-width: 480px media query. At the bottom of the media query, add the following rule as shown below in bold:
img.shim { display: block!important; width: 100%!important; }
NOTE: Make sure you do not have a space between block and !important to avoid an issue in Yahoo.
- Save the file.
- Reload the page in Chrome.
- The browser window should still be narrow to show the mobile view, but take some time to resize the window in out and in again to compare the mobile view to the desktop view. The ALT text should read Date Night Mobile on the mobile view.
- Return to your code editor.
-
Now that we know it works, we can edit the ALT text so it reads correctly. In the shim image (around line 137), delete the word Mobile from the ALT text so it reads as follows:
<img src="http://www.nobledesktop.com/nl-date-night/img/shim.gif" width="1" height="1" ALT="Date Night" align="center" class="shim">
- Save the file.
- Reload the page in Chrome to see the correct ALT text.
- We’re finished so you should turn image back on. Switch back to the Settings tab that should still be open in Chrome.
- Click the toggle button to the right of Do not show any images.
- Switch back to the tab with your email.
Reload the page and you should be able to see all the images again.