PHPackages                             hocvt/emogrifier - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. hocvt/emogrifier

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

hocvt/emogrifier
================

Converts CSS styles into inline style attributes in your HTML code

V1.3.5(8y ago)02731MITPHPPHP &gt;=5.4.0, &lt;=7.2.99

Since Oct 30Pushed 8y ago1 watchersCompare

[ Source](https://github.com/vuthaihoc/emogrifier)[ Packagist](https://packagist.org/packages/hocvt/emogrifier)[ Docs](https://www.myintervals.com/emogrifier.php)[ RSS](/packages/hocvt-emogrifier/feed)WikiDiscussions hocvt Synced 3w ago

READMEChangelog (3)Dependencies (2)Versions (12)Used By (0)

Emogrifier
==========

[](#emogrifier)

[![Build Status](https://camo.githubusercontent.com/a76abbc92435bd432a5133d859d3cbefce6d1379958e781c199d9c770fb12268/68747470733a2f2f7472617669732d63692e6f72672f6a6a7269762f656d6f677269666965722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jjriv/emogrifier)[![Latest Stable Version](https://camo.githubusercontent.com/73b02dfada4c5c2ce1b12dcf94936025254db69d9ed5d4a8a853f5dbb89f5a17/68747470733a2f2f706f7365722e707567782e6f72672f70656c61676f2f656d6f677269666965722f762f737461626c652e737667)](https://packagist.org/packages/pelago/emogrifier)[![Total Downloads](https://camo.githubusercontent.com/fbc9036fb2e16b3c4be97f32c1eaec1732b93356ef12d5e0b29da7efb54a04ff/68747470733a2f2f706f7365722e707567782e6f72672f70656c61676f2f656d6f677269666965722f646f776e6c6f6164732e737667)](https://packagist.org/packages/pelago/emogrifier)[![Latest Unstable Version](https://camo.githubusercontent.com/413640e3c618f2fe231bdb1a1580e34e3cc3e1ef1309652c4b452d5984cc72d2/68747470733a2f2f706f7365722e707567782e6f72672f70656c61676f2f656d6f677269666965722f762f756e737461626c652e737667)](https://packagist.org/packages/pelago/emogrifier)[![License](https://camo.githubusercontent.com/2b1df5be5c79eb3f2cb899bd1f7687a6c7cf8ca2b1b13d19edc51203b62228b6/68747470733a2f2f706f7365722e707567782e6f72672f70656c61676f2f656d6f677269666965722f6c6963656e73652e737667)](https://packagist.org/packages/pelago/emogrifier)

*n. e•mog•ri•fi•er \[\\ē-'mä-grƏ-,fī-Ər\] - a utility for changing completely the nature or appearance of HTML email, esp. in a particularly fantastic or bizarre manner*

Emogrifier converts CSS styles into inline style attributes in your HTML code. This ensures proper display on email and mobile device readers that lack stylesheet support.

This utility was developed as part of [Intervals](http://www.myintervals.com/)to deal with the problems posed by certain email clients (namely Outlook 2007 and GoogleMail) when it comes to the way they handle styling contained in HTML emails. As many web developers and designers already know, certain email clients are notorious for their lack of CSS support. While attempts are being made to develop common [email standards](http://www.email-standards.org/), implementation is still a ways off.

The primary problem with uncooperative email clients is that most tend to only regard inline CSS, discarding all `` elements and links to stylesheets in `` elements. Emogrifier solves this problem by converting CSS styles into inline style attributes in your HTML code.

- [How it works](#how-it-works)
- [Installation](#installation)
- [Usage](#usage)
- [Options](#options)
- [Requirements](#requirements)
- [Installing with Composer](#installing-with-composer)
- [Supported CSS selectors](#supported-css-selectors)
- [Caveats](#caveats)
- [Maintainer](#maintainer)

How it Works
------------

[](#how-it-works)

Emogrifier automagically transmogrifies your HTML by parsing your CSS and inserting your CSS definitions into tags within your HTML based on your CSS selectors.

Installation
------------

[](#installation)

For installing emogrifier, either add pelago/emogrifier to your project's composer.json, or you can use composer as below:

```
composer require pelago/emogrifier

```

Usage
-----

[](#usage)

First, you provide Emogrifier with the HTML and CSS you would like to merge. This can happen directly during instantiation:

```
$html = 'Hello world!';
$css = 'h1 {font-size: 32px;}';
$emogrifier = new \Pelago\Emogrifier($html, $css);

```

You could also use the setters for providing this data after instantiation:

```
$emogrifier = new \Pelago\Emogrifier();

$html = 'Hello world!';
$css = 'h1 {font-size: 32px;}';

$emogrifier->setHtml($html);
$emogrifier->setCss($css);

```

After you have set the HTML and CSS, you can call the `emogrify` method to merge both:

```
$mergedHtml = $emogrifier->emogrify();

```

Emogrifier automatically adds a Content-Type meta tag to set the charset for the document (if it is not provided).

If you would like to get back only the content of the BODY element instead of the complete HTML document, you can use the `emogrifyBodyContent` instead:

```
$bodyContent = $emogrifier->emogrifyBodyContent();

```

Options
-------

[](#options)

There are several options that you can set on the Emogrifier object before calling the `emogrify` method:

- `$emogrifier->disableStyleBlocksParsing()` - By default, Emogrifier will grab all `` blocks in the HTML and will apply the CSS styles as inline "style" attributes to the HTML. The `` blocks will then be removed from the HTML. If you want to disable this functionality so that Emogrifier leaves these `` blocks in the HTML and does not parse them, you should use this option. If you use this option, the contents of the `` blocks will *not* be applied as inline styles and any CSS you want Emogrifier to use must be passed in as described in the [Usage section](#usage) above.
- `$emogrifier->disableInlineStylesParsing()` - By default, Emogrifier preserves all of the "style" attributes on tags in the HTML you pass to it. However if you want to discard all existing inline styles in the HTML before the CSS is applied, you should use this option.
- `$emogrifier->disableInvisibleNodeRemoval()` - By default, Emogrifier removes elements from the DOM that have the style attribute `display: none;`. If you would like to keep invisible elements in the DOM, use this option.
- `$emogrifier->addAllowedMediaType(string $mediaName)` - By default, Emogrifier will keep only media types `all`, `screen` and `print`. If you want to keep some others, you can use this method to define them.
- `$emogrifier->removeAllowedMediaType(string $mediaName)` - You can use this method to remove media types that Emogrifier keeps.
- `$emogrifier->addExcludedSelector(string $selector)` - Keeps elements from being affected by emogrification.
- `$emogrifier->enableCssToHtmlMapping()` - Some email clients don't support CSS well, even if inline and prefer HTML attributes. This function allows you to put properties such as height, width, background color and font color in your CSS while the transformed content will have all the available HTML tags set.

Requirements
------------

[](#requirements)

- PHP from 5.4 to 7.0
- or HHVM

Installing with Composer
------------------------

[](#installing-with-composer)

Download the [`composer.phar`](https://getcomposer.org/composer.phar) locally or install [Composer](https://getcomposer.org/) globally:

```
curl -s https://getcomposer.org/installer | php

```

Run the following command for a local installation:

```
php composer.phar require pelago/emogrifier:@dev

```

Or for a global installation, run the following command:

```
composer require pelago/emogrifier:@dev

```

You can also add follow lines to your `composer.json` and run the `composer update` command:

```
"require": {
  "pelago/emogrifier": "@dev"
}

```

See  for more information and documentation.

Supported CSS selectors
-----------------------

[](#supported-css-selectors)

Emogrifier currently support the following [CSS selectors](http://www.w3.org/TR/CSS2/selector.html):

- ID
- class
- type
- descendant
- child
- adjacent
- attribute presence
- attribute value
- attribute value with |
- attribute value with ~
- attribute value with ^
- attribute value with \*
- attribute value with $
- attribute only
- first-child
- last-child

The following selectors are not implemented yet:

- universal
- pseudo-elements (will never be supported)

Caveats
-------

[](#caveats)

- Emogrifier requires the HTML and the CSS to be UTF-8. Encodings like ISO8859-1 or ISO8859-15 are not supported.
- Emogrifier now preserves all valuable @media queries. Media queries can be very useful in responsive email design. See [media query support](https://litmus.com/help/email-clients/media-query-support/).
- Emogrifier will grab existing inline style attributes *and* will grab `` blocks from your HTML, but it will not grab CSS files referenced in elements. (The problem email clients are going to ignore these tags anyway, so why leave them in your HTML?)
- Even with styles inline, certain CSS properties are ignored by certain email clients. For more information, refer to these resources:
    -
    -
    -
- All CSS attributes that apply to a node will be applied, even if they are redundant. For example, if you define a font attribute *and* a font-size attribute, both attributes will be applied to that node (in other words, the more specific attribute will not be combined into the more general attribute).
- There's a good chance you might encounter problems if your HTML is not well-formed and valid (DOMDocument might complain). If you get problems like this, consider running your HTML through [Tidy](http://php.net/manual/en/book.tidy.php) before you pass it to Emogrifier.
- Emogrifier automatically converts the provided (X)HTML into HTML5, i.e., self-closing tags will lose their slash. To keep your HTML valid, it is recommended to use HTML5 instead of one of the XHTML variants.
- Emogrifier only supports CSS1 level selectors and a few CSS2 level selectors (but not all of them). It does not support pseudo selectors. (Emogrifier works by converting CSS selectors to XPath selectors, and pseudo selectors cannot be converted accurately).

Maintainer
----------

[](#maintainer)

Emogrifier is maintained by the good people at [Pelago](http://www.pelagodesign.com/), info AT pelagodesign DOT com.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 85.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~146 days

Recently: every ~117 days

Total

10

Last Release

2939d ago

Major Versions

v0.1.1 → V1.0.02015-10-14

PHP version history (5 changes)v0.0.1PHP &gt;=5.3.0

v0.1.1PHP &gt;=5.4.0

V1.1.0PHP &gt;=5.4.0,&lt;=7.1.99

V1.2.1PHP &gt;=5.4.0, &lt;=7.1.99

v1.3.2PHP &gt;=5.4.0, &lt;=7.2.99

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2509658?v=4)[Stupid Dev](/maintainers/vuthaihoc)[@vuthaihoc](https://github.com/vuthaihoc)

---

Top Contributors

[![oliverklee](https://avatars.githubusercontent.com/u/765746?v=4)](https://github.com/oliverklee "oliverklee (236 commits)")[![jjriv](https://avatars.githubusercontent.com/u/4063419?v=4)](https://github.com/jjriv "jjriv (7 commits)")[![vanderlee](https://avatars.githubusercontent.com/u/649240?v=4)](https://github.com/vanderlee "vanderlee (4 commits)")[![vuthaihoc](https://avatars.githubusercontent.com/u/2509658?v=4)](https://github.com/vuthaihoc "vuthaihoc (4 commits)")[![erikhansen](https://avatars.githubusercontent.com/u/129031?v=4)](https://github.com/erikhansen "erikhansen (3 commits)")[![sanderkruger](https://avatars.githubusercontent.com/u/1422536?v=4)](https://github.com/sanderkruger "sanderkruger (3 commits)")[![Renkas](https://avatars.githubusercontent.com/u/5357180?v=4)](https://github.com/Renkas "Renkas (3 commits)")[![mistic100](https://avatars.githubusercontent.com/u/41597?v=4)](https://github.com/mistic100 "mistic100 (2 commits)")[![Synchro](https://avatars.githubusercontent.com/u/81561?v=4)](https://github.com/Synchro "Synchro (2 commits)")[![timothyasp](https://avatars.githubusercontent.com/u/707699?v=4)](https://github.com/timothyasp "timothyasp (1 commits)")[![acorncom](https://avatars.githubusercontent.com/u/802505?v=4)](https://github.com/acorncom "acorncom (1 commits)")[![white43](https://avatars.githubusercontent.com/u/10009618?v=4)](https://github.com/white43 "white43 (1 commits)")[![adduc](https://avatars.githubusercontent.com/u/44527?v=4)](https://github.com/adduc "adduc (1 commits)")[![bramley](https://avatars.githubusercontent.com/u/3147688?v=4)](https://github.com/bramley "bramley (1 commits)")[![captn3m0](https://avatars.githubusercontent.com/u/584253?v=4)](https://github.com/captn3m0 "captn3m0 (1 commits)")[![demis-palma](https://avatars.githubusercontent.com/u/1609992?v=4)](https://github.com/demis-palma "demis-palma (1 commits)")[![IonelScutelnicu](https://avatars.githubusercontent.com/u/2164778?v=4)](https://github.com/IonelScutelnicu "IonelScutelnicu (1 commits)")[![jorrit](https://avatars.githubusercontent.com/u/521449?v=4)](https://github.com/jorrit "jorrit (1 commits)")[![joubertredrat](https://avatars.githubusercontent.com/u/1520407?v=4)](https://github.com/joubertredrat "joubertredrat (1 commits)")[![Seldaek](https://avatars.githubusercontent.com/u/183678?v=4)](https://github.com/Seldaek "Seldaek (1 commits)")

---

Tags

cssemailpre-processing

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/hocvt-emogrifier/health.svg)

```
[![Health](https://phpackages.com/badges/hocvt-emogrifier/health.svg)](https://phpackages.com/packages/hocvt-emogrifier)
```

###  Alternatives

[pelago/emogrifier

Converts CSS styles into inline style attributes in your HTML code

94745.9M132](/packages/pelago-emogrifier)[egulias/email-validator

A library for validating emails against several RFCs

11.6k719.7M402](/packages/egulias-email-validator)[sendgrid/sendgrid

This library allows you to quickly and easily send emails through Twilio SendGrid using PHP.

1.5k49.8M183](/packages/sendgrid-sendgrid)[zbateson/mail-mime-parser

MIME email message parser

54651.9M86](/packages/zbateson-mail-mime-parser)[soundasleep/html2text

A PHP script to convert HTML into a plain text format

48020.6M85](/packages/soundasleep-html2text)[inlinestyle/inlinestyle

Apply CSS stylesheets directly as inline styles to a HTML document

140650.8k12](/packages/inlinestyle-inlinestyle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
