Inline CSS
Automatically inline CSS from<style> tags in your HTML emails.
CSS inlining is still important in HTML email, mainly because of Outlook on Windows, which doesn’t support multiple classes on elements.
It can also help preserve a decent layout in email clients that do not support embedded CSS (in <style> tags), or when an email is forwarded.
The utility-first approach in Tailwind CSS works great with CSS inlining: utility classes are not ‘global’, so you won’t end up with a font-family inlined on every element (unless you really, really want to).
Usage
To enable CSS inlining, simply setcss.inline to true in your config:
config.js
You will want to keep CSS inlining off when developing AMP4EMAIL templates
Customization
If you need control over how your CSS is inlined, you may pass a configuration object toinlineCSS. Doing this in your Environment config.js will enable CSS inlining for all Templates when building for that Environment.
styleToAttribute
Defines which CSS properties should be duplicated as what HTML attributes.
config.js
| CSS Property | HTML Attribute |
|---|---|
background-color | bgcolor |
background-image | background |
text-align | align |
vertical-align | valign |
attributeToStyle
Duplicates specified HTML attributes as inline CSS.
applyWidthAttributes
Whether to use any CSS pixel widths to create
width attributes on elements set in css.inline.widthElements.false to prevent any width attributes from being added based on inline CSS width:
config.js
widthElements
Array of HTML elements that can receive
width attributes based on inline CSS width.config.js
applyHeightAttributes
Whether to use any CSS pixel heights to create
height attributes on elements set in css.inline.heightElements.false to prevent any height attributes from being added based on inline CSS height:
config.js
heightElements
Array of HTML elements that can receive
height attributes based on inline CSS height.config.js
excludedProperties
Array of CSS property names that should be excluded from the CSS inlining process.
config.js
--tw-shadow is automatically excluded from the properties that can be inlined.codeBlocks
An object where each value has a start and end to specify fenced code blocks that should be ignored during CSS inlining.
removeInlinedSelectors
When
css.inline is enabled, classes will be removed from the class attribute of a tag after they have been successfully inlined.false to preserve the classes in the class attribute.
config.production.js
preferUnitlessValues
When inlining CSS,
0 values will be inlined without units.margin: 0px will be inlined as margin: 0.
Set this to false to keep units on 0 values.
config.js
useAttributeSizes
Prefer HTML
width and height attributes over inline CSS.true to use HTML attributes for sizes instead of inline CSS:
config.js
useAttributeSizes will apply to all elements defined in widthElements and heightElementssafelist
An array of strings representing CSS selectors that should not be removed after inlining.
text-red to preserve .text-red, .text-red-500, etc.
config.js
Prevent inlining
You may add an attribute on a<style> tag to prevent Juice from inlining the CSS inside it. Useful for writing email client CSS hacks, or for preserving CSS comments when using the removeCSSComments: false Cleanup option.
data-embedno-inlineembed
CSS selectors that don’t appear in your markup will still need to be whitelisted for purging.
API
You can use theinlineCSS function to inline CSS in a string of HTML.
Your HTML string will need to have at least one <style> tag in the <head>.
Alternatively, you may pass your own CSS to inline through the customCSS option.
Additionally, you may configure the Juice library by passing options in the same object.
app.js