# style-data

> Get the content of style tags.

Latest version **2.0.2** (published 2024-12-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install style-data
pnpm add style-data
yarn add style-data
bun add style-data
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2024-12-27 |
| First published | 2015-01-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 438 |
| Author | Jonathan Kemp |
| Maintainers | jonkemp |
| Keywords | inline, css, html, email |

## Links

- npm: https://www.npmjs.com/package/style-data
- Repository: https://github.com/jonkemp/inline-css.git#master
- Homepage: https://github.com/jonkemp/inline-css/tree/master/packages/style-data
- Issues: https://github.com/jonkemp/inline-css/issues
- npm.io page: https://npm.io/package/style-data

## Dependencies (3)

- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0
- [pick-util](https://npm.io/package/pick-util.md) ^1.1.5
- [mediaquery-text](https://npm.io/package/mediaquery-text.md) ^1.2.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2024-12-27
- 2.0.1 — 2023-02-08
- 2.0.0 — 2022-07-08
- 1.4.8 — 2022-01-17
- 1.4.7 — 2020-10-24
- 1.4.6 — 2020-02-21
- 1.4.5 — 2020-01-26
- 1.4.4 — 2020-01-26
- 1.4.3 — 2020-01-25
- 1.4.2 — 2020-01-25
- 1.4.1 — 2020-01-19
- 1.4.0 — 2019-11-11
- 1.3.3 — 2019-10-08
- 1.3.2 — 2018-10-25
- 1.3.1 — 2018-10-24
- … 12 more at https://npm.io/package/style-data/versions

## README

# style-data

[![NPM](https://nodei.co/npm/style-data.png?downloads=true)](https://nodei.co/npm/style-data/)

> Get the content of style tags.

## Install

Install with [npm](https://npmjs.org/package/style-data)

```
npm install --save style-data
```

## Usage

```js
var getStylesData = require('style-data');

getStylesData(html, options, function (err, results) {
    console.log(results.html);  // resulting html
    console.log(results.css);   // array of css rules
});
```

## API

### getStylesData(html, options, callback)

#### options.applyStyleTags

Type: `Boolean`  
Default: `true`

Whether to inline styles in `<style></style>`.

#### options.removeStyleTags

Type: `Boolean`  
Default: `true`

Whether to remove the original `<style></style>` tags after (possibly) inlining the css from them.

#### options.preserveMediaQueries

Type: `Boolean`  
Default: `false`

Preserves all media queries (and contained styles) within `<style></style>` tags as a refinement when `removeStyleTags` is `true`. Other styles are removed.

#### options.codeBlocks

Type: `Object`  
Default: `{ EJS: { start: '<%', end: '%>' }, HBS: { start: '{{', end: '}}' } }`

An object where each value has a `start` and `end` to specify fenced code blocks that should be ignored during parsing. For example, Handlebars (hbs) templates are `HBS: {start: '{{', end: '}}'}`. Note that `codeBlocks` is a dictionary which can contain many different code blocks, so don't do `codeBlocks: {...}` do `codeBlocks.myBlock = {...}`.

### Special markup

#### data-embed

When a data-embed attribute is present on a <style></style> tag, style-data will not inline the styles and will not remove the <style></style> tags.

This can be used to embed email client support hacks that rely on css selectors into your email templates.

### cheerio options

Options to passed to [cheerio](https://github.com/cheeriojs/cheerio).

## Credit

The code for this module was originally taken from the [Juice](https://github.com/Automattic/juice) library.

## License

MIT © [Jonathan Kemp](http://jonkemp.com)

---
_Source: https://npm.io/package/style-data · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
