tijsverkoyen /CssToInlineStyles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very usefull when you're sending emails.

★ 5,817⑂ 192👁 51⑃ 138● 123▤ 11
PHPBSD-3-ClauseCreated 2010-10-25
下载:2.4.02.4.0 ↓2.4.02025-12-11
+0
日增长
5,817
stars
192
forks
51
watchers
138
prs
123
issues
11
releases

README

CssToInlineStyles class



 About

CssToInlineStyles is a class that enables you to convert HTML-pages/files into
HTML-pages/files with inline styles. This is very useful when you're sending
emails.

 Installation

The recommended installation way is through Composer.

bash
$ composer require tijsverkoyen/css-to-inline-styles


 Example

php
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;

// create instance
$cssToInlineStyles = new CssToInlineStyles();

$html = file_get_contents(__DIR__ . '/examples/sumo/index.htm');
$css = file_get_contents(__DIR__ . '/examples/sumo/style.css');

// output
echo $cssToInlineStyles-convert(
    $html,
    $css
);


 Known issues

 no support for pseudo selectors
 no support for css-escapes
 UTF-8 charset is not always detected correctly. Make sure you set the charset to UTF-8 using the following meta-tag in the head: . _(Note: using  does NOT work!)_

 Sites using this class

 Each site based on Fork CMS
 Print en Bind
 Tiki Wiki CMS Groupware (starting in Tiki 13)
 Laravel Framework

Top issues

Latest release

2.4.0 v2.4.0 2025-12-11
What's Changed
 Allow Symfony 8 by @nicolas-grekas in https://github.com/tijsverkoyen/CssToInlineStyles/pull/255
 PHP 8.5: Replace deprecated SplObjectStorage::contains with offsetExists by @MrPunyapal in https://github.com/tijsverkoyen/CssToInlineStyles/pull/257

 New Contributors
 @MrPunyapal made their first contribution in https://github.com/tijsverkoyen/CssToInlineStyles/pull/257

Full Changelog: https://github.com/tijsverkoyen/CssToInlineStyles/compare/v2.3.0...v2.4.0

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON