Below is a simple responsive email template with an explanatory comment for each section of the code. This template includes a responsive banner image and some content. The code is designed to ensure compatibility with the Gmail app on mobile devices:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Email Template</title>
<style>
/* Inline CSS styles for compatibility with email clients */
@media only screen and (max-width: 600px) {
/* Adjust styles for mobile devices */
.container {
width: 100% !important;
padding: 0 !important;
}
.banner img {
width: 100% !important;
height: auto !important;
}
}
</style>
</head>
<body style="margin: 0; padding: 0; font-family: Arial, sans-serif;">
<!-- Container table for email content -->
<table class="container" role="presentation" width="600" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td style="padding: 20px;">
<!-- Banner section with responsive image -->
<div class="banner">
<img src="https://via.placeholder.com/600x200" alt="Banner Image" style="display: block; width: 100%; height: auto;">
</div>
<!-- Content section -->
<div style="padding: 20px; background-color: #f9f9f9;">
<h2>Welcome to Our Newsletter</h2>
<p>Thank you for subscribing to our newsletter. Here's the latest updates...</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tristique massa eu orci hendrerit, eget varius justo interdum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
<p>Nunc malesuada, magna nec euismod varius, velit risus maximus libero, nec consequat arcu sem a ex. Duis sit amet ullamcorper nibh. Nulla facilisi. Integer eu lectus sit amet augue hendrerit facilisis.</p>
<p>Quisque euismod ex sit amet neque iaculis, at vehicula velit consequat. Sed id elit ac nibh mollis hendrerit.</p>
</div>
</td>
</tr>
</table>
</body>
</html>
Explanation of the code:
The <meta viewport> tag ensures proper scaling on mobile devices.
The <style> block contains CSS styles, including media queries for responsive design.
Inside the media query, .container width is set to 100% to ensure full-width display on mobile.
The .banner img styles ensure the banner image scales correctly on smaller screens.
The HTML structure consists of a table-based layout, which is widely supported in email clients.
The banner image is wrapped inside a <div class="banner"> to style it separately.
Content is placed inside a <div> with padding and a background color for better readability.
Placeholder image (600x200) is used for the banner image (https://via.placeholder.com/600x200). Replace this with your actual banner image URL.