spyc.ai

Free tool

Email CSS Inliner

Move style block rules into inline style attributes for HTML email, and list the selectors left behind.

How it works

What is the Email CSS Inliner?

The Email CSS Inliner is a free tool that copies CSS rules from a style block into style attributes on the matching elements, the format HTML email needs. It inlines tag, class, ID and descendant selectors, and leaves pseudo-classes, media queries and other unsupported rules in the style block, listing each one.

How to use the Email CSS Inliner

  1. Paste your email HTML, including its style block, or press Load sample.
  2. Check how many selectors were inlined and how many were left in the style block.
  3. Read the list of rules that were not inlined and decide whether you need them.
  4. Press Copy HTML and send a test email before the real one.

What is CSS inlining?

Inlining moves each CSS declaration out of a stylesheet and into the style attribute of every element it applies to. A rule such as p { margin: 0; } disappears from the style block and every p tag gains style="margin: 0;".

The page looks the same in a browser. The difference is that the styling now travels with each element and does not depend on the style block surviving.

Why do HTML emails need inline CSS?

Email clients are far less consistent than browsers. Support for style blocks varies between clients and between versions of the same client, and styles in the head can be dropped in some situations, for example when a message is forwarded. External stylesheets are not loaded by most clients at all.

Inline styles are the most widely supported way to style an email, which is why inlining is the standard last step before sending. Write your CSS in a style block where it is easy to maintain, then inline it.

Which selectors does this inliner support?

Tag selectors such as p, class selectors such as .button, ID selectors such as #header, combinations such as td.cell or a.button.primary, and descendant selectors built from those, such as .card h1. Comma-separated lists are split and each selector is handled on its own.

Not supported, and left in the style block exactly as written: pseudo-classes and pseudo-elements such as :hover and ::before, attribute selectors, the child and sibling combinators >, + and ~, the universal selector, and all at-rules including @media, @font-face and @import. The tool lists every one it left behind. Some of these, such as :hover, cannot be expressed as an inline style in any tool.

How are conflicting rules resolved?

The way a browser would resolve them, within the supported selectors. More specific selectors win: an ID beats a class, a class beats a tag. Between equal selectors, the later rule wins. A declaration marked !important beats one that is not.

A style attribute already on an element beats the style block, unless the rule in the block is !important. The !important flag itself is not written into the inline style, because once a declaration is inline it no longer needs it, and leaving it out lets a media query in the style block still override the inline value on clients that support media queries.

What should I check after inlining?

First the list of rules left in the style block. If your layout depends on a child combinator or an attribute selector, rewrite that rule with a class and run the tool again. Second, the markup: the HTML is parsed and written back by your browser, so attribute quotes are normalized and missing tags, such as tbody inside a table, are added. Shorthand properties such as margin are copied as written and not expanded.

Then send a real test to the clients your audience uses. No inliner can tell you how Outlook or Gmail will render the result. Inlining also makes the file larger, and Gmail is widely reported to clip messages over roughly 102 KB, so run the result through the HTML and CSS Minifier if it is close. For campaign links in the email, the UTM Builder adds tracking parameters.

Questions

Does Gmail support style blocks?
Gmail supports style blocks in the head and some media queries in many cases, but not in all of its apps and account types. Inline styles remain the dependable baseline.
What happens to my media queries?
They stay in the style block unchanged. A media query cannot be inlined, because an inline style has no way to express a condition.
Does the inliner remove the style block?
It removes the rules it inlined, and drops rules whose selector matches nothing in the HTML. If any unsupported rules remain, the style block is kept with only those rules. If none remain, the block is removed.
Can it inline an external stylesheet?
No. It makes no network requests. Paste the CSS into a style tag in the HTML and it will be processed.
Is the Email CSS Inliner free?
Yes, with a free spyc.ai account. It runs in your browser, so nothing you type or paste is sent to a server.

Developer Tools

More in Developer Tools

JSON Formatter

Format, minify and validate JSON in your browser, with the line and column of the first syntax error.

Format JSON

JSON-LD Formatter

Pretty-print JSON-LD pasted bare or in script tags, list every @type and flag a missing @context.

Format JSON-LD

Case Converter

Convert text to upper, lower, title or sentence case, or to camelCase, PascalCase, snake_case and kebab-case.

Convert case

Ready when you are

Before your next buyer asks AI about you, ask AI about yourself

One check, four engines, about twenty seconds. We show you the answers before we ask for anything.