---
title: "Inline CSS plugin"
description: "takes TinyMCE documents and outputs HTML formatted according to email-friendly HTML best practices (eg inlined CSS)."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/inline-css/"
md_url: "https://www.tiny.cloud/docs/tinymce/6/inline-css/index.md"
version: "6"
last_updated: "2023-04-06T02:03:43Z"
tokens: 1977
---
Important This page documents TinyMCE 6. For new projects, Tiny recommends using the latest, most up-to-date version. [See TinyMCE 8 documentation](../../latest/inline-css/).
# Inline CSS plugin

> **Note:** This plugin is only available for [paid TinyMCE subscriptions](/pricing/).

> **Note:** This feature is only available for TinyMCE 6.3 and later.
As is normal and long-time best practice, TinyMCE documents keep CSS and HTML separate. This practice is not, however, email-friendly.

The Inline CSS plugin takes a TinyMCE document, and processes it such that the previously separate CSS is applied inline to each HTML element. This single output file is much closer to the common requirements for sending as an HTML-formatted email.

## Interactive example

**Example**

```js
const settings = {
  plugins: [
    'advlist', 'anchor', 'autolink', 'charmap', 'code', 'fullscreen',
    'help', 'image', 'insertdatetime', 'link', 'lists', 'media',
    'preview', 'searchreplace', 'table', 'visualblocks', 'inlinecss'
  ],
  toolbar: 'undo redo | styles | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
  content_style: `
    .red {
      color: red;
    }
    .blue {
      color: blue;
    }
    .blue-background {
      background-color: blue;
    }
    .red-background {
      background-color: red;
    }
  `
};

tinymce.init({
  selector: 'textarea.classic',
  ...settings
});

const button = document.getElementById('inline-css-btn');
const outputTextArea = document.getElementById('output-text-area');

button.addEventListener('click', () => {
  const pluginAPI = tinymce.get(0).plugins.inlinecss;
  const outputIframe = document.getElementById('outputIframe');
  const rawDoc = outputIframe.contentWindow.document;
  pluginAPI.getContent().then((content) => {
    outputTextArea.value = content.html;

    if (rawDoc) {
      rawDoc.open();
      rawDoc.write(content.html);
      rawDoc.close();
    }
  });
});
```

## Basic setup

To add the Inline CSS plugin to the editor, add `inlinecss` to the `plugins` option in the editor configuration.

For example:

```js
tinymce.init({
  selector: 'textarea',  // change this value according to your HTML
  plugins: 'inlinecss',
});
```

## Usage notes

The Inline CSS plugin does not support

1. [Pseudo-classes](https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes).

For example:

```css
button:hover {
  color: blue;
}
```
2. [Pseudo-elements](https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements).

For example:

```css
p::first-line {
  color: blue;
}
```
3. [@ rules](https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule).

For example:

```html
@media (screen)
```
4. The `!important` property.

### Classic or iframe mode support

[Classic or iframe mode](../use-tinymce-classic/) is a sandbox. Consequently, specifying CSS is constrained.

CSS can be specified in classic mode in the following ways:

1. The `content_css` option

Setting the [`content_css`](../add-css-options/#content_css) option automatically creates the `<link>` tag and puts it in the TinyMCE document’s `<head>`.

> **Note:** This is the only supported way of adding a stylesheet to TinyMCE in Classic mode.
2. The `content_style` option

Setting the [`content_style`](../add-css-options/#content_style) option automatically creates the `<style>` tag and puts it in the TinyMCE document’s `<head>`.

> **Note:** This is the only supported way of adding a `<style>` tag to TinyMCE in Classic mode.
3. A CSS stylesheet specified in the `<head>` of the iframe with a `<link>` tag.

For example:

```html
<link rel="stylesheet" href="styles.css">
```
4. A `<style>` tag in the `<head>` of the iframe.

For example:

```html
<style>p { color: red; }</style>
```
5. `style` attributes applied to specific elements within a document. That is, inline CSS

> **Note:** By default, TinyMCE does not support `<style>` tags in the document `<body>`.

### Inline mode support

[Inline mode](../use-tinymce-inline/) is not sandboxed. Consequently, any specified CSS can effect how editor content presents.

CSS can be specified in inline mode in the following ways:

1. The `content_css` option

Setting the [`content_css`](../add-css-options/#content_css) option automatically creates the `<link>` tag and puts it in the TinyMCE document’s `<head>`.

> **Note:** This is not recommended.
2. A CSS stylesheet specified in the `<head>` of the document with a `<link>` tag.

For example:

```html
<head>
<link rel="stylesheet" href="styles.css">
</head>
```
3. A CSS stylesheet specified in the `<body>` of the document.

For example:

```html
<body>
<link rel="stylesheet" href="styles.css">
</body>
```

> **Important:** This is [not recommended](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link). Some browsers allow it, however, and it is, as a consequence, honored by TinyMCE when presented.
4. A `<style>` tag in the `<head>` of the document.

For example:

```html
<style>p { color: red; }</style>
```
5. A `<style>` tag can also be manually inserted in the document `<head>`.
6. `style` attributes applied to specific elements within a document. That is, inline CSS

> **Note:** By default, TinyMCE does not support `<style>` tags in the document `<body>`.

### Shadow DOM support

> **Important:** Running a TinyMCE instance inside a Shadow DOM is [not supported](../shadow-dom/).
Although running neither TinyMCE nor the Inline CSS plugin in a Shadow DOM is supported, when a TinyMCE instance *is* in a shadow root, the Inline CSS will likely still present

- CSS specified by the `content_css` option; and
- CSS specified by the `content_style` option

as expected, whether running in [Classic mode](../use-tinymce-classic/) or [Inline mode](../use-tinymce-inline/).

## Options

The following configuration options affect the behavior of the Inline CSS plugin.

### inline_selector_filter

Determines whether it is valid for a given CSS selector to have its CSS properties inlined into the HTML content

Default: All selectors are considered valid to have their CSS inlined

Type: `String` `RegExp` or `Function`

```ts
inlinecss_selector_filter: (selector: string): boolean => {
  return selector.indexOf('myprefix') !== -1;
}
```

### inline_file_filter

Determines whether it is valid for a given CSS stylesheet to have its CSS inspected and inlined into the HTML content

Default: All CSS stylesheet are considered valid to have their CSS inspected and inlined

Type: `String` `RegExp` or `Function`

```ts
inlinecss_file_filter: (href: string): boolean => {
  return selector.indexOf('mystyles') !== -1;
}
```

## Events

The Inline CSS plugin provides the following events.

The following events are provided by the [Inline CSS plugin](#).

| Name | Data | Description |
| --- | --- | --- |
| InlineCSS | N/A | Fired when inlining the CSS begins. |

## APIs

The Inline CSS plugin provides the following APIs.

A new API, `editor.plugins.inlinecss.getContent();` has been added to support the new `InlineCSS` plugin

The API’s function is to take a TinyMCE document, and processes it such that the previously separate CSS is applied inline to each HTML element.
The `editor.plugins.inlinecss.getContent();` API does not require configuration from the user

The API will do the following

- Fire the 'InlineCSS' event
- Get the editor’s content by calling the `editor.plugins.inlinecss.getContent();`
- Collect all of the stylesheets defined by the `content_css` option
- Collect all styles specified in the `content_style` option
- Combine `content_css` and `content_style` styles while making sure `content_style` has a higher precedent
- Iterate over the content within the TinyMCE editor viewport, by inlining any `InlineCSS` styles where it finds a selector match
- Return an object that contains the content with `InlineCSS` as a `string`

## Example

```ts
interface PluginAPI {
  getContent: () => Promise<{
    html: string;
  }>
}
```
Result output after the `InlineCSS` content has been applied by the API

```js
{
  html: '<p style="color: red;">hello</p>'
}
```
