Can I Use Media Queries In Email Template
- Tips & Resources
Email designers take long sought to build campaigns for every device. Especially today, when roughly half of all email opens happen on mobile devices, it'south important to blueprint an experience that works well across different form factors. While this used to be a difficult job (and still is for some e-mail clients), media queries can brand this task easier.
But, unless y'all've been mired in the world of spider web blueprint, you may not know what media queries are and why you should utilize them. In this blog post, we'll dissect the ever-useful media query and see why information technology is a must-use in every email.
What is a media query?
Media queries are a component of cascading style sheets (CSS), the language used to style websites and e-mail campaigns. At its about basic level, media queries act as a switch for triggering styles based on a set of rules. So, how does that switch work?
A media query consists of three parts: the media blazon, an expression, and the mode rules independent within the media query itself.
The media blazon allows usa to declare what blazon of of media the rules should exist applied to. There are four options you can declare: all, impress, screen, and speech. For the purposes of e-mail, yous tin nearly ever use the screen blazon.
Expressions allow you to farther target devices based on specific weather condition you laissez passer the media query. Expressions test media features, which describe different features of a device, such as width, height, aspect-ratio, and colour. While there are many media features you tin can test, near e-mail designers rely on the following:
- max- and min-width
- max- and min-device-width
- device-pixel-ratio
Media features tin too exist combined within the media query to provide greater control over targeting devices and clients. We'll see an case of this when nosotros talk about advanced media query use.
Finally, inside the media query's curly braces, CSS rules can be exist toggled when the email is opened on a device that satisfies both the media blazon and expressions.
Media queries need to be included within a style cake which is typically located in the head of your HTML. This has implications when it comes to how we write our CSS rules and back up for media queries, both of which we'll hash out afterwards.
The benefits of media queries
Using media queries, we can fine-tune email designs then that they are more than usable across a broad range of devices. Let's look at a common scenario.
For a long time, email designers built their emails using a desktop-only approach. The electronic mail uses fixed table widths and everything is optimized to look good on desktop and webmail clients. However, when viewed on mobile devices, the design breaks downwardly: the electronic mail is zoomed to fit, making the text and buttons likewise minor to tab; the layout is broken and unusable; or the correct-side of the email is hidden from view, making horizontal scrolling necessary.
Prior to the use of media queries, there was little a designer could do to overcome these problems. Now, we tin can use media queries to target mobile devices and suit our styles appropriately.
A quick instance
If you've read our guide to mobile approaches, you know that stock-still-width emails are typically scaled downward on mobile devices, leading to small-scale, unreadable text. Fluid emails, which apply per centum-based widths, let content to catamenia and fill various screen sizes.
So, let's say we have a container table with a stock-still width of 600 pixels. In this scenario, nosotros desire to switch that fixed width of 600 pixels in desktop views to a fluid, percentage-based width (100%) on smaller screens.
<tabular array edge="0" cellpadding="0" cellspacing="0" width="600" grade="container-table"> You'll notice that a grade has been added to the container table. We can attain the fixed-to-fluid switch by using classes to name and target HTML elements, and using our media query to override the styles applied to the tabular array. Every class needs a name, and in this case, we've named ours .container-table. We suggest giving classes obvious names that speak to their purpose in your media query.
/* TYPICAL Web Blueprint METHOD */ .container-table {} Once we've added the form name to the table tag, we'll need to add together the media query to theof our HTML, along with an expression and the same class proper name. The expression we've used, max-width: 600px, tells the media query to apply the rules any time the screen size is less than 600px wide.
@media screen and (max-width:600px) { .container-table { } } At present, nosotros'll add together the style rules that adjust the value of the CSS width belongings for that table. Now our container table is fluid on any viewport narrower than 600 pixels.
@media screen and (max-width:600px) { .container-table { width: 100% !of import; } } This same approach can be used to arrange common pain points on mobile such as text, image, and button sizes. For example, if we desire to adjust the text size of our re-create on mobile, we can do so in a virtually identical fashion:
@media screen and (max-width:600px) { .mobile-text { font-size: 18px !of import; } } By targeting class names or specific elements, we can manipulate our designs and brand them more readable and usable on smaller devices.
It should be noted that, in most cases, we are using media queries to override inline styles. If you are familiar with how CSS works, the pour uses the order of declaring CSS rules to make up one's mind which styles should exist rendered. Since media queries naturally alive at the top of an HTML document, any inline styles applied to the content of the email volition accept precedence. Therefore, we need a manner to override those inline styles.
This can exist accomplished using the !important declaration:
td { font-size: 24px !important; font-weight: assuming !of import; } A lot of spider web designers rail against the overuse of the !important annunciation merely, for e-mail designers, information technology's our best friend.
Advanced targeting
While a lot of electronic mail designers will just ever employ media queries to adjust styles for mobile devices, they can be used in more avant-garde means, too.
There are a lot of coding and design techniques that simply don't work in some email clients. Things like SVG, CSS animations, and video are amazing when you tin can get away with them but, when done poorly, can ruin the feel for subscribers viewing in outdated email clients. One of the most valuable uses of media queries is to target specific email clients or platforms and progressively raise content, so that those cutting-border techniques can be used without worrying about breaking the experience for anybody else.
A great case of this is our popular email featuring a background video which we sent to promote our first Litmus Live event. Video in email has long been considered the holy grail of email design. While a few clients support it, most don't. Instead of attempting to shove the video into anybody's inbox, our designer, Kevin, used media queries to target simply those clients that support video in email and enhanced the entrada for that audience.
Video backgrounds are only supported past certain Webkit-based browsers, namely Apple Mail and Outlook 2011 for Mac. While other electronic mail clients saw a background color and background image (when supported), thank you to the following media query, the Webkit-based clients saw a full-width video playing in the background:
@media screen and (-webkit-min-device-pixel-ratio: 0) { /* Insert styles here */ } Similar expressions can be used to target a whole host of devices based on their features. For example, if yous wanted to target the iPhone X in standard view, you tin use the following:
@media screen and (device-width : 375px) and (device-peak : 812px) and (-webkit-device-pixel-ratio : 3) { /* Insert styles hither */ } Using media queries to target specific email clients or platforms gives email designers previously unheard of command over their designs. When combined with things like CSS animations, designers can deliver truly phenomenal experiences correct in the inbox.
Support
Support for media queries in electronic mail clients across mobile, webmail, and desktop has improved over the years—near popular electronic mail clients support media queries! Check out this support tabular array to see where media queries are supported:
| Media Query Support in E-mail Clients | |
| Mobile | |
| Android 4.4 | |
| Gmail app (Android) | |
| Gmail app IMAP (Android) | |
| iOS | |
| Inbox by Gmail (Android) | |
| Inbox by Gmail (iOS) | |
| Outlook (Android) | |
| Outlook (iOS) | |
| Samsung Mail (Android) | |
| Yahoo! Mail service app (Android) | |
| Yahoo! Mail app (iOS) | |
| Desktop | |
| Apple tree Mail ten | |
| Outlook 2000-03 | |
| Outlook 2007-xvi | |
| Outlook for Mac | |
| Thunderbird | |
| Windows ten Mail | |
| Webmail | |
| AOL Mail service | |
| Gmail | |
| G Suite | |
| GMX.de | |
| Inbox by Gmail | |
| Libero | |
| Role 365 | |
| Orangish.fr | |
| Outlook.com | |
| Gmail | |
| SFR.fr | |
| T-online.de | |
| Web.de | |
| Yahoo! Mail | |
This varying degree of support is why we typically recommend building a solid foundation for your email using HTML and inline CSS, with media queries added in to progressively enhance the blueprint. The hybrid arroyo to building emails is the perfect foundation for when media queries aren't supported.
Improve your campaigns
Media queries let designers to build experiences for a wider range of devices than always before. More chiefly, they let you lot to fine-melody your designs for an increasingly mobile audience. As with any new technique, it's important to exam your campaigns to make certain they look great.
Get responsive with one of our pre-tested responsive templates
| Litmus Community TemplatesKickstart your next campaign with one of Litmus' pre-tested templates. Admission the templates → |
Can I Use Media Queries In Email Template,
Source: https://www.litmus.com/blog/understanding-media-queries-in-html-email/#:~:text=While%20a%20lot%20of%20email,work%20in%20some%20email%20clients.
Posted by: johnsonequallown.blogspot.com

0 Response to "Can I Use Media Queries In Email Template"
Post a Comment