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
+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 FrameworkTop issues
#241Typed property DOMDocument::$documentElement must not be accessed before initialization12 comments · 2023-01-30#161Void elements are no longer closed when using xhtml7 comments · 2016-09-21#206Any plans on adding CSS variables support?6 comments · 2021-04-07#133Inlining inside conditional comments5 comments · 2016-04-06#174<script> tag styling4 comments · 2017-11-20#170Class Error on first load4 comments · 2017-09-28#226Add ability to override existing inline styles2 comments · 2022-04-15#207Cannot handle Excessive depth error2 comments · 2021-04-22
Latest release
2.4.0 v2.4.0 2025-12-11What'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