PHPackages                             northys/css-inliner - 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. northys/css-inliner

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

northys/css-inliner
===================

PHP Library that converts css file into html inline styles.

v1.0-beta(10y ago)4316.8k↓69.7%4[2 issues](https://github.com/Northys/CSS-Inliner/issues)LGPLPHP

Since Sep 29Pushed 9y ago8 watchersCompare

[ Source](https://github.com/Northys/CSS-Inliner)[ Packagist](https://packagist.org/packages/northys/css-inliner)[ RSS](/packages/northys-css-inliner/feed)WikiDiscussions master Synced yesterday

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

CSS-Inliner
-----------

[](#css-inliner)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8782fdfede167793e604736b823bec8c8cc4d2349cbf4d28537ed66ab7b22478/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f72746879732f4353532d496e6c696e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/northys/CSS-Inliner)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/4f39599c39755c0fbe80e87ef449840c3dafcb6a3ea76fb640fb2a5a591533e0/68747470733a2f2f7472617669732d63692e6f72672f4e6f72746879732f4353532d496e6c696e65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Northys/CSS-Inliner)[![Total Downloads](https://camo.githubusercontent.com/5d9afc77e4b441767fc6a6f3dbc3dd2d3aabf8ef4290bf7c8eb1c415f1a19b78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6f72746879732f4353532d496e6c696e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/northys/CSS-Inliner)

CSS-Inliner is simple PHP tools that **inserts CSS from file into HTML style attributes**. Nothing more, nothing less.

I tried to make it **as fast as possible**, but due to third party libraries I can't do more.

Anyway, this tools wasn't created for **inlining CSS files of bambilions lines (hey, [Bootstrap](http://getbootstrap.com) - of course you can inline it, but you will have enough time to make a coffee)**, but for inlining styles into e-mails. So I hope it will do its job for you and helps you with creating newsletters, sending notification mails and so on.

Usage
-----

[](#usage)

### Installation using composer

[](#installation-using-composer)

Add northys/css-inliner to your composer.json. It is necessary to install this tools using composer. Otherwise you will need to download another libs manually.

```
$ composer require northys/css-inliner
```

### Requirements

[](#requirements)

- [sabberworm/PHP-CSS-Parser](https://github.com/sabberworm/PHP-CSS-Parser)
- [Symfony/CssSelector](https://github.com/symfony/CssSelector)

### Example code

[](#example-code)

```
$inliner = new Northys\CSSInliner;
$inliner->addCSS(__DIR__ . '/example.css');
$inliner->render(file_get_contents(__DIR__ . '/example.html'));
```

Method `addCSS()` accepts file path to the CSS file however `render()` accepts html content. If you would like to know why, here is the reason for you - there are tons of templating system like `Nette\Latte` or `Smarty` and sometimes you will need to use this tool on code that those libs generated.

#### Input

[](#input)

```
Hello, world!
Google
Facebook
Outlook
```

```
h1{color:#27ae60;font-size:200px;margin:10px 50px 80px 30px;}
a{color:#2c3e50;}
a#outlook{color:#2980b9;position:absolute;top:30px;left:500px;padding:50px;}
a.facebook{color:#8e44ad;margin:300px;}
a.google{color:#c0392b;font-weight:700;font-family:Verdana, 'Open Sans';font-size:30px;}
```

#### Output

[](#output)

```
Hello, world!
Google
Facebook
Outlook
```

### Or run it with node

[](#or-run-it-with-node)

1. Install dependencies

```
	npm install
```

2. Run

```
	node index example myResult
```

A file myResult.html will be genereted in templates/example.

Your .html and .css files must be the same name of your template path. See an example in

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.2% 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 ~0 days

Total

2

Last Release

3930d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2878126?v=4)[Northys](/maintainers/Northys)[@northys](https://github.com/northys)

---

Top Contributors

[![northys](https://avatars.githubusercontent.com/u/2878126?v=4)](https://github.com/northys "northys (41 commits)")[![alisonmonteiro](https://avatars.githubusercontent.com/u/3016692?v=4)](https://github.com/alisonmonteiro "alisonmonteiro (12 commits)")[![fprochazka](https://avatars.githubusercontent.com/u/158625?v=4)](https://github.com/fprochazka "fprochazka (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/northys-css-inliner/health.svg)

```
[![Health](https://phpackages.com/badges/northys-css-inliner/health.svg)](https://phpackages.com/packages/northys-css-inliner)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[blackfire/player

A powerful web crawler and web scraper with Blackfire support

49617.1k](/packages/blackfire-player)[spatie/laravel-pjax

A pjax middleware for Laravel 5

523386.8k11](/packages/spatie-laravel-pjax)[chameleon-system/chameleon-base

The Chameleon System core.

1028.6k5](/packages/chameleon-system-chameleon-base)[dominikb/composer-license-checker

Utility to check for licenses of dependencies and block/allow them.

574.6M14](/packages/dominikb-composer-license-checker)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M343](/packages/drupal-core-dev)

PHPackages © 2026

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