Sharp, responsive images that render well on both mobile and desktop
Since pretty much all of today's mobile devices have high pixel density screens, you need to use "retina" images for your media to look sharp on any screen. This is done by using images that are usually twice (or even more!) the intended display size.
However, some email clients - specifically Outlook for desktop - don't like images that are larger than their container, and will blow up your design if you don't use a fixed width.
Pine uses fluid retina images, so they display well across the board. Even in Outlook.
Fluid Retina Images
Not only does this ensure proper image sizing in all email clients, but your mobile images will not expand beyond their natural width.
Simply use the width=""
attribute on an <img>
tag, to set a fixed width that is half the natural image width. This is the intended display width, and will work in all email clients, including Outlook.
On mobile, Pine will ensure your image scales proportionally and doesn't exceed its container width:
<table cellpadding="0" cellspacing="0" role="presentation" width="100%">
<tr>
<td style="padding: 30px 20px;">
<table cellpadding="0" cellspacing="0" role="presentation" width="100%">
<tr>
<td class="col" width="640" style="padding: 0 10px;">
<h2 style="font-weight: 300;">Fluid Retina</h2>
<img src="https://picsum.photos/1280/1280?image=631" alt="Image 1" width="640">
</td>
</tr>
<tr>
<td class="col" width="640" style="padding: 0 10px;">
<h2 style="font-weight: 300;">Fluid Non-Retina</h2>
<img src="https://picsum.photos/640/640?image=631" alt="Image 2" width="640">
</td>
</tr>
</table>
</td>
</tr>
</table>
Note: the example is using a 1280x1280 image for retina, and a 640x640 one for non-retina. The difference is best viewed on a high-density display, like on a smartphone.
Mobile Full Width
Sometimes, you may need to have a retina image expand to 100% of its container width on mobile.
Since Pine prevents this by default (through max-width: 100%;
), you can use the full-width-sm
utility class on the <img>
tag, to force it to full width on mobile:
<img class="full-width-sm" src="..." alt="..." width="123">
Caution
Although it may not be noticeable on large images, keep in mind that this will render non-retina images larger than their natural width, making them look blurry or pixelated.
Hiding Images on Desktop
While our hide-sm
utility class is enough to hide an image in mobile email clients, things get a bit more complicated on desktop. You can hide images on desktop and only show them on mobile just like we do with the hamburger navigation icon:
<!--[if !mso ]><!-->
<img class="show-sm" src="https://picsum.photos/640/400?image=1025" width="600" style="display: none; max-height: 0;">
<!--<![endif]-->
The inline CSS and Outlook conditional comment will hide the image for desktop email clients, while the show-sm
class will make it visible on mobile devices.
Tip
Always use aria-hidden="true"
on hidden or UI images - it'll help screen readers skip them.