How to Inline CSS in HTML Emails (The Right Way)
The CSS Inlining Problem
When you build a website, you write CSS in separate .css files or <style> blocks in the <head> of your HTML. The browser reads those stylesheets and applies the rules to matching elements. This is clean, maintainable, and has worked reliably for decades.
Email clients don't work this way. Gmail strips everything in a <style> block. Yahoo Mail does the same. Outlook is inconsistent about which rules it respects from <head> styles. The result: if you send an HTML email with styles in a stylesheet rather than inline on each element, most of your styles simply won't apply.
Inline CSS — styles written directly in the style attribute of each HTML element — is the only formatting that works reliably across all major email clients. But maintaining inline CSS by hand is tedious, error-prone, and results in bloated HTML that's nearly impossible to update.
CSS inlining tools solve this: you write normal CSS in a <style> block, then run the inliner, which processes your selectors and converts them to inline styles before you send. The output is compatible with even the most restrictive email clients, while your source file remains maintainable.
How CSS Inlining Works
A CSS inliner parses your HTML, reads the CSS rules in your <style> block, finds every element that matches each selector, and writes the computed style directly into that element's style attribute. The <style> block is either removed or left in place (depending on the tool's settings).
For example, this source code:
<style>
.button {
background-color: #6b21a8;
color: #ffffff;
padding: 12px 24px;
border-radius: 6px;
text-decoration: none;
font-weight: bold;
}
</style>
...
<a href="https://postdrop.io" class="button">Try Postdrop</a>
After inlining, becomes:
<a href="https://postdrop.io"
style="background-color:#6b21a8;color:#ffffff;padding:12px 24px;border-radius:6px;text-decoration:none;font-weight:bold;"
>Try Postdrop</a>
The original class attribute remains (it's harmless), but the visual styling is now fully portable across email clients.
What Doesn't Get Inlined
Not all CSS properties can be inlined. Certain constructs fundamentally can't work as element-level inline styles:
Media Queries
Media queries require a <style> block — there's no way to express a breakpoint condition as an inline style. A well-configured inliner preserves media queries in the <style> block rather than trying to inline them. For clients that strip <style> blocks (Gmail Android), this means responsive behavior won't work — an acceptable compromise since those clients typically don't need responsive layout anyway, as they already resize content to fit.
Pseudo-Classes and Pseudo-Elements
:hover, :focus, :first-child, and similar selectors can't be inlined. Many email clients support basic pseudo-class CSS in <style> blocks, so inliners typically leave these in place rather than stripping them.
Dark Mode Rules
The @media (prefers-color-scheme: dark) block must stay in the <style> tag. Any dark mode overrides you define in this block are preserved by inliners that support this pattern.
CSS Specificity After Inlining
CSS specificity becomes interesting once everything is inlined. Inline styles have the highest specificity — they override anything in a <style> block. This is actually what you want for the base styles. But it means that if you're relying on <style> block rules to override inline styles (for responsive behavior or dark mode), those won't work as expected.
The solution: use !important declarations in your media query overrides to ensure they win over the inlined base styles. This sounds like a hack, but it's the accepted pattern in email development:
@media only screen and (max-width: 600px) {
.two-col {
width: 100% !important;
display: block !important;
}
}
The !important ensures the mobile width override wins against the inlined desktop width, even though inline styles normally take precedence.
CSS Inlining Tools
Postdrop.io
Postdrop.io handles CSS inlining automatically as part of its workflow. When you build or paste your email HTML in the editor, it inlines your styles before generating client previews and before you export. You get the benefits of writing maintainable stylesheet CSS while the output is fully inlined for client compatibility.
Juice
Juice is the most popular open-source Node.js CSS inlining library. It's the engine under the hood of many inlining tools. You can use it as a command-line tool or integrate it into your build pipeline.
Premailer
Premailer is a Ruby gem (and web service) that pioneered CSS inlining for email. It handles specificity conflicts well and preserves media queries. The web interface at premailer.dialect.ca accepts HTML or a URL and returns inlined HTML.
Mailchimp's CSS Inliner
Mailchimp provides a free web-based CSS inliner at templates.mailchimp.com/resources/inline-css/. It's straightforward: paste your HTML, click a button, get inlined output.
Practical Inlining Workflow
Here's a workflow that keeps your source files maintainable while producing inlined output for sending:
- Write your email in a template file with a <style> block containing all your CSS. Organize styles by component (header, body, button, footer) for readability.
- Keep responsive CSS in media queries in the <style> block. Use
!importanton properties that need to override inlined values. - Run the inliner (or build Postdrop.io into your workflow) to generate the send-ready HTML.
- Test the inlined output — not the source file — because that's what subscribers will receive. Verify it looks correct in your target clients.
- Never edit the inlined output directly. Make all changes in the source file and re-inline. If you edit the inlined HTML, you'll lose those changes the next time you inline.
Common Inlining Mistakes
Using Shorthand Properties
Some email clients don't support shorthand CSS properties like font: bold 16px/1.5 Arial. Prefer individual properties: font-weight: bold; font-size: 16px; line-height: 1.5; font-family: Arial. Inliners may or may not expand shorthands, so it's safer to avoid them in your source.
Forgetting About Email Client CSS Resets
Some email clients inject their own stylesheets that affect your content. Gmail adds default link colors. Outlook adds default line heights. After inlining, verify that these injected styles aren't overriding your carefully applied inline values.
Inlining Everything Including Width
Inlining pixel widths on <table> elements is correct. But don't inline percentage widths — they won't work in Outlook. Use the HTML width attribute for percentage widths on table cells that need to be percentage-based, alongside the inline style for pixel widths.
CSS inlining is one of the less glamorous parts of HTML email development, but getting it right is the foundation everything else builds on. Once you have a reliable inlining step in your workflow — whether that's using Postdrop.io's automatic inlining or running Juice in your build script — your cross-client compatibility improves dramatically, and you can focus on writing good CSS rather than debugging why styles aren't applying.