# Juice  [![CI][github-ci-shield]][github-ci]  [![License][license-shield]][license] Given HTML, Juice will inline your CSS properties into the `style` attribute. [Some projects using Juice →](PROJECTS.md) ## How to use Juice has a number of functions based on whether you want to process a file, HTML string, or a cheerio document, and whether you want Juice to automatically get remote stylesheets, scripts and image dataURIs to inline. To inline HTML without getting remote resources, using default options: ```js import juice from 'juice'; const result = juice("
"); ``` `result` will be: ```html ``` [Try out the web client version](https://automattic.github.io/juice/) ## What is this useful for? - HTML emails. For CSS support in email clients see [Can I Email](https://www.caniemail.com/). - Embedding HTML in 3rd-party websites. ## Documentation Juice is exposed as a standard module, and from CLI with a smaller set of options. ### Modern CSS support Juice handles modern CSS out of the box: **nested rules** (CSS Nesting Module Level 1, `.card { &:hover { ... } }`) are flattened automatically before inlining, **`@container`** and **`@layer`** at-rules pass through verbatim, and specificity for **`:is()`** / **`:where()`** / **`:has()`** / **`:not()`** is computed per the CSS Selectors Level 4 spec. ### Options All Juice methods take an options object that can contain any of these properties, though not every method uses all of these: | Option | Default value | Description | |--------|-------|------------| | `applyAttributesTableElements` | `true` | Create attributes for styles in `juice.styleToAttribute` on elements set in `juice.tableElements`. | | `applyHeightAttributes` | `true` | Use any CSS pixel heights to create `height` attributes on elements set in `juice.heightElements`. | | `applyStyleTags` | `true` | Inline styles in ` ``` The `data-embed` attribute will be removed from the output HTML, but no inlining or style tag removal will take place: ```html ``` #### data-juice-duplicates Override the [`inlineDuplicateProperties`](#options) option for a single element by adding `data-juice-duplicates` to it. The attribute presence (or `data-juice-duplicates="true"`) enables duplicate declarations for that element; `data-juice-duplicates="false"` disables them: ```html ``` The `data-juice-duplicates` attribute is removed from the output HTML. #### data-juice-important Override the [`preserveImportant`](#options) option for a single element by adding `data-juice-important` to it. The attribute presence (or `data-juice-important="true"`) preserves `!important` in that element's inlined declarations; `data-juice-important="false"` strips it: ```html ``` The `data-juice-important` attribute is removed from the output HTML. ### Ignoring CSS with comments You can use special CSS comments to prevent Juice from inlining entire CSS files, rules, or even just declarations. #### Ignore entire file Add a `/* juice ignore */` comment on the first line in your CSS: ```html