Sub topic 9
Responsive images and handling blocked images
This chapter assumes you can write the table layout and inline CSS from the earlier chapters. It covers two jobs: making images scale with the screen, and making the email still work when images don't load.
How images behave in email
Images are the part of an email most likely to fail. Many clients block remote images until the reader allows them. Some corporate Outlook setups never show them. Even when images load, a fixed 600px image overflows a 375px phone screen. Plan for both problems from the start.
Scaling images to the container
Use three layers, so every client gets a workable result:
- HTML
widthandheightattributes with the image's natural display size. Desktop Outlook reads these and ignores most CSS sizing. - Inline
max-width:100%andheight:auto. Most mobile clients apply these, so the image shrinks with its cell. display:blockandborder:0. These remove the small gap below images and the blue border some clients add to linked images.
<table role='presentation' width='100%' cellpadding='0' cellspacing='0' border='0'>
<tr>
<td align='center' bgcolor='#e8eefc' style='background-color:#e8eefc;'>
<img src='https://example.com/img/hero-1200.png' width='600' height='300' alt='Spring sale: 20% off all jackets' style='display:block;width:100%;max-width:600px;height:auto;border:0;font-family:Arial,Helvetica,sans-serif;font-size:18px;line-height:24px;color:#222222;'>
</td>
</tr>
</table>The file is 1200px wide but displays at 600px. This gives sharp results on high-density phone screens (often called retina). The width attribute tells clients the display size, so the file's size doesn't set the layout.
Handling blocked images
When images are blocked, the browser or client shows the alt text in the space where the image would be. Three details make that fallback usable:
- Write alt text that carries the message, such as "Spring sale: 20% off all jackets". Don't write "banner".
- Style the
imgwith font, size, and color, as in the example above. Alt text uses those styles in most clients. - Set a background color on the cell behind the image. The area then keeps its shape and the text stays readable.
Giving the img explicit width and height also stops the layout from collapsing when the image doesn't load.
Stacking and swapping images on phones
If an image sits in a column that stacks on phones, add a class and force full width in your media query:
<style>
@media screen and (max-width: 600px) {
.fluid-img { width: 100% !important; height: auto !important; }
}
</style>Add class='fluid-img' to the img tag. The inline height:auto already helps, and the !important rules win over the inline values in clients that read the style block.
Common errors
| Problem | Cause | Fix |
|---|---|---|
| Small gap under an image | Images are inline by default | Add `display:block` |
| Image overflows on phones | Fixed width with no `max-width` | Add `max-width:100%; height:auto` |
| Image stretched in Outlook | `height:auto` with no height attribute | Set both `width` and `height` attributes |
| Blank space when blocked | No alt text, no background color | Add styled alt text and `bgcolor` |
| Blurry image on phones | File is only as wide as its display size | Use a file about twice the display width |
Keep file sizes modest. A hero image over a few hundred kilobytes loads slowly on mobile data, and slow images are more likely to be skipped. Use JPEG for photos and PNG for flat graphics. Animated GIFs show only the first frame in some Outlook versions, so make that frame carry the message.
Exercise
A 600px-wide banner is exported as a 1200px file. Which attributes and styles keep it sharp on retina screens, shrinkable on phones, and readable when blocked?
Show answer
Set width='600' and height to match the 600px display size, and add style display:block; width:100%; max-width:600px; height:auto; border:0. Add descriptive alt text with font, size, and color styles, and put a background color on the cell behind the image.