# juice **Repository Path**: mirrors_jfromaniello/juice ## Basic Information - **Project Name**: juice - **Description**: Juice inlines CSS stylesheets into your HTML source. - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-25 - **Last Updated**: 2026-05-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [](https://travis-ci.org/Automattic/juice) [](https://david-dm.org/Automattic/juice) # Juice  Given HTML, juice will inline your CSS properties into the `style` attribute. ## 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 var juice = require('juice'); var result = juice("
"); ``` result will be: ```html ``` ## What is this useful for ? - HTML emails. For a comprehensive list of supported selectors see [here](http://www.campaignmonitor.com/css/) - Embedding HTML in 3rd-party websites. ## Projects using juice * [node-email-templates][1] - Node.js module for rendering beautiful emails with [ejs][2] templates and email-friendly inline CSS using [juice][3]. * [swig-email-templates][4] - Uses [swig][5], which gives you [template inheritance][6], and can generate a [dummy context][7] from a template. [1]: https://github.com/niftylettuce/node-email-templates [2]: https://github.com/visionmedia/ejs [3]: https://github.com/Automattic/juice [4]: https://github.com/superjoe30/swig-email-templates [5]: https://github.com/paularmstrong/swig [6]: https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance [7]: https://github.com/superjoe30/swig-dummy-context ## Documentation ### Options All juice methods take an options object that can contain any of these properties, though not every method uses all of these: * `extraCss` - extra css to apply to the file. Defaults to `""`. * `applyStyleTags` - whether to inline styles in `` Defaults to `true`. * `removeStyleTags` - whether to remove the original `` tags after (possibly) inlining the css from them. Defaults to `true`. * `preserveMediaQueries` - preserves all media queries (and contained styles) within `` tags as a refinement when `removeStyleTags` is `true`. Other styles are removed. Defaults to `false`. * `applyWidthAttributes` - whether to use any CSS pixel widths to create `width` attributes on elements set in `juice.widthElements`. Defaults to `false`. * `applyAttributesTableElements` - whether to create attributes for styles in `juice.styleToAttribute` on elements set in `juice.tableElements`. Defaults to `false`. * `webResources` - An options object that will be passed to [web-resource-inliner](https://www.npmjs.com/package/web-resource-inliner) for juice functions that will get remote resources (`juiceResources` and `juiceFile`). Defaults to `{}`. * `inlinePseudoElements` - Whether to insert pseudo elements (`::before` and `::after`) as `` into the DOM. *Note*: Inserting pseudo elements will modify the DOM and may conflict with CSS selectors elsewhere on the page (e.g., `:last-child`). ### Methods #### juice(html [, options]) Returns string containing inlined HTML. Does not fetch remote resources. * `html` - html string, accepts complete documents as well as fragments * `options` - optional, see Options above #### juice.juiceResources(html, options, callback) Callback returns string containing inlined HTML. Fetches remote resources. * `html` - html string * `options` - see Options above * `callback(err, html)` - `err` - `Error` object or `null` - `html` - inlined HTML #### juice.juiceFile(filePath, options, callback) Callback returns string containing inlined HTML. Fetches remote resources. * `filePath` - path to the html file to be juiced * `options` - see Options above * `callback(err, html)` - `err` - `Error` object or `null` - `html` - inlined HTML #### juice.juiceDocument($ [, options]) Returns string containing inlined HTML. Does not fetch remote resources. * `$` - a cheerio instance, be sure to use the same cheerio version that juice uses * `options` - optional, see Options above` #### juice.inlineContent(html, css [, options]) This takes html and css and returns new html with the provided css inlined. It does not look at `