Works on this device
Email CSS Inliner
Many mail programs drop or limit the style blocks of an email, so the styles must stand in each tag. Paste the HTML of your email, and this page writes the rules of its <style> blocks into style attributes. Rules that cannot be inlined, such as media queries, stay in the style block. The HTML is read as text in your browser and is never run.
Your email
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your HTML with inline CSS will show here
Paste the HTML, or choose Try an example.
Result
How it was worked out
How to use the inliner
- Paste the HTML source of your email, with its
<style>blocks, or open the file. - Choose what stays in the style block. The first choice keeps only what cannot be inlined, such as
@mediarules and:hover. - Choose Inline the CSS. The result is the new HTML source. The table lists every rule with its specificity, the number of elements it matched and what happened to it.
- Copy the HTML or download it, and send a test message to the mail programs that matter to you.
Which declaration wins
When two rules set the same property of one element, the page follows the cascade of CSS. A rule with a higher specificity wins: an id counts more than a class, and a class counts more than a tag name. When the specificity is the same, the rule that comes later in the source wins.
A style attribute that the element already has wins over the style blocks. A declaration with !important in a style block wins over that attribute. A declaration with !important in the attribute itself wins over everything.
The declarations are written in that order, the weakest first. So a short form such as margin and a long form such as margin-top end up in the order in which a browser would apply them. When one property is set by several rules, only the one that wins is written.
What can be inlined
- Selectors that are matched: tag names,
*, classes, ids and attribute selectors ([href],[href^="https"]and the other forms), joined by a space,>,+or~, and lists with commas. - Pseudo-classes that are matched:
:first-child,:last-child,:only-child,:first-of-type,:last-of-type,:only-of-type,:nth-child(),:nth-last-child(),:nth-of-type(),:nth-last-of-type()withodd,even, a number or a form such as2n+1, and also:root,:emptyand:not()around simple selectors. - Kept in the style block: selectors that depend on a state or on a part of an element, such as
:hover,:focus,:visited,:link,::beforeand::first-line, and the forms:is(),:where(),:has()and:lang(). A style attribute cannot say these. To give every link a style, write the rule foraand not fora:link. - Kept in the style block:
@media,@font-face,@importand every other @ rule. The rules inside@mediaare not looked at. - Left alone: a rule with a selector that cannot be read, with a pseudo-class that the page does not know, or with the new flag
sin an attribute test. A browser that cannot read a selector drops the whole rule, so the page does not inline any part of it. - Not read: a
<style>block with the attributedata-embedordata-premailer="ignore", with amediaattribute other thanallorscreen, or with a type that is nottext/css. Linked style sheets are not read, because the page loads nothing.
Worked example
The example on this page has one style block with 8 style rules and one @media rule. The rule p { margin: 0 0 16px 0; } matches both paragraphs. The rule p.note { color: #666666; font-size: 13px; } matches the second one, which already has style="margin-bottom: 0".
The second paragraph gets style="margin: 0 0 16px 0; color: #666666; font-size: 13px; margin-bottom: 0;". The rule p comes first because its specificity 0,0,1 is the lowest, then p.note with 0,1,1, and the paragraph's own margin-bottom comes last, so it still wins over the margin of the rule.
In all, 7 selectors are inlined, 7 elements get a style attribute, and 16 declarations are written. The rule a:hover and the @media rule stay in the style block.
Old attributes for tables and images
Under More options the page can also write three old HTML attributes, which some older mail programs follow better than CSS. Each one is written by one rule, and a tag that already has the attribute keeps it.
widthontable,td,thandimg, from awidthin whole pixels (600pxgiveswidth="600"). Ontable,tdandthalso from a percentage (100%giveswidth="100%").bgcoloronbody,table,tr,tdandth, from abackground-colorwritten as#and 6 digits, or#and 3 digits, which is written out as 6. Colour names andrgb()give no attribute.alignontdandth, from atext-alignofleft,center,rightorjustify.
Limits you should know
- Test the result in the mail programs that matter to you. Mail programs do not all follow the same CSS, and this page does not know which properties each program takes.
- The HTML is read as text and is never drawn. Tags that a browser adds by itself (
html,head,body,tbody) are not added. Sotable > trmatches here when the source has notbodytag, andtbody > trdoes not. - A kept rule such as
a:hovercan only win over an inlined property when it has!important, because a style attribute is stronger than a style block. - Inherited properties, such as the colour of text, are not copied to child elements. Only the elements that a selector matches get the declarations.
- Properties and values are not checked. A property that no program knows is written as it is, and short forms such as
marginare not taken apart. When several rules set one property, only the one that wins is written, also if a mail program does not know its value. A browser would then fall back to the weaker rule. - Broken HTML is read with the usual repair rules. Where a browser repairs in a way of its own, for example a link inside a link, the elements can be counted differently.
- Class names, ids and attribute values are compared exactly as written, with their capital letters. Tag and attribute names are compared without them.
- A selector that matches no element is taken out of the style block all the same. If your email tool adds content with those classes later, choose to keep the whole style block.
- Rules nested inside a rule are not read. An address written without quotes that holds
/*is read as the start of a comment. - Only the changed start tags and the style blocks are rewritten. Line ends are written as LF. The largest input is 500,000 characters.
- For the plain text part of the message, use the Email Plain Text Converter.