PHPackages                             janormman/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. janormman/emogrifier

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

janormman/emogrifier
====================

Copy of pelagios emogrifier. Converts CSS styles into inline style attributes in your HTML code

1(11y ago)02.1kMITPHPPHP &gt;=5.3.0

Since Apr 17Pushed 11y ago1 watchersCompare

[ Source](https://github.com/JANorman/emogrifier)[ Packagist](https://packagist.org/packages/janormman/emogrifier)[ Docs](http://www.pelagodesign.com/sidecar/emogrifier/)[ RSS](/packages/janormman-emogrifier/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

Emogrifier
==========

[](#emogrifier)

Clone of the original library....

[![Build Status](https://camo.githubusercontent.com/6efaf702c6c1a3748e8d8d99b187ec1889e089758943eb65bc07c88f0477702a/68747470733a2f2f7472617669732d63692e6f72672f6a6a7269762f656d6f677269666965722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/jjriv/emogrifier)[![Latest Stable Version](https://camo.githubusercontent.com/f7e7894725f67acbd25af04a9dc441496df1915198ae16179e37c5e98f6d1387/68747470733a2f2f706f7365722e707567782e6f72672f70656c61676f2f656d6f677269666965722f762f737461626c652e706e67)](https://packagist.org/packages/pelago/emogrifier)[![Total Downloads](https://camo.githubusercontent.com/e2f2feebdc4b98e03def9172b0b7ca90cf3ca442974753974da8f18c78523b70/68747470733a2f2f706f7365722e707567782e6f72672f70656c61676f2f656d6f677269666965722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/pelago/emogrifier)[![Latest Unstable Version](https://camo.githubusercontent.com/5179e132193bb17c4d5591c11f5794afe9d0a4876ef78adf27b20ec8d9e40f89/68747470733a2f2f706f7365722e707567782e6f72672f70656c61676f2f656d6f677269666965722f762f756e737461626c652e706e67)](https://packagist.org/packages/pelago/emogrifier)[![License](https://camo.githubusercontent.com/9821ed6d41687edacecaac2764ec77c255d4aef903c8d0736ca6f25b30af3174/68747470733a2f2f706f7365722e707567782e6f72672f70656c61676f2f656d6f677269666965722f6c6963656e73652e706e67)](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 Google Gmail) 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)
- [Usage](#usage)
- [Installing with Composer](#installing-with-composer)
- [Usage](#usage)
- [Supported CSS selectors](#supported-css-selectors)
- [Caveats](#caveats)
- [Maintainer](#maintainer)
- [Contributing](#contributing)

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.

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();

```

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:*

```

Or for a global installation, run the following command:

```
composer require pelago/emogrifier:*

```

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

```
"require": {
  "pelago/emogrifier": "*"
}

```

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 only

The following selectors are implemented, but currently are broken:

- first-child (currently broken)
- last-child (currently broken)

The following selectors are not implemented yet:

- universal

Caveats
-------

[](#caveats)

- Emogrifier requires the HTML and the CSS to be UTF-8. Encodings like ISO8859-1 or ISO8859-15 are not supported.
- **NEW:** 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/).
- **NEW:** 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, review documentation [here](http://www.email-standards.org/).
- 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.
- Finally, 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.

Contributing
------------

[](#contributing)

Those that wish to contribute bug fixes, new features, refactorings and clean-up to Emogrifier are more than welcome. When you contribute, please take the following things into account:

- Please cover all changes with unit tests and make sure that your code does not break any existing tests.
- Please use the same coding style as the rest of the code. Indentation is four spaces.
- Please make your code clean, well-readable and easy to understand.
- If you add new methods or fields, please use proper PHPDoc for the new methods/fields.
- Git commits should have a &lt;= 50 character summary, optionally followed by a blank line and a more in depth description of 79 characters per line.
- [Please squash related commits together](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html).
- Please use grammatically correct, complete sentences in the code documentation and the commit messages.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.4% 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

Unknown

Total

1

Last Release

4320d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/180341?v=4)[James Norman](/maintainers/JANorman)[@JANorman](https://github.com/JANorman)

---

Top Contributors

[![oliverklee](https://avatars.githubusercontent.com/u/765746?v=4)](https://github.com/oliverklee "oliverklee (70 commits)")[![jjriv](https://avatars.githubusercontent.com/u/4063419?v=4)](https://github.com/jjriv "jjriv (6 commits)")[![mistic100](https://avatars.githubusercontent.com/u/41597?v=4)](https://github.com/mistic100 "mistic100 (2 commits)")[![captn3m0](https://avatars.githubusercontent.com/u/584253?v=4)](https://github.com/captn3m0 "captn3m0 (1 commits)")[![IonelScutelnicu](https://avatars.githubusercontent.com/u/2164778?v=4)](https://github.com/IonelScutelnicu "IonelScutelnicu (1 commits)")[![JANorman](https://avatars.githubusercontent.com/u/180341?v=4)](https://github.com/JANorman "JANorman (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[stephenjude/laravel-wallet

A simple wallet implementation for Laravel

26411.7k](/packages/stephenjude-laravel-wallet)[lara-zeus/matrix-choice

Zeus Matrix Choice multiple choice grid component form for filamentPHP

2225.6k](/packages/lara-zeus-matrix-choice)[jalendport/craft-readtime

Calculate the estimated read time for content.

1052.3k](/packages/jalendport-craft-readtime)

PHPackages © 2026

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