mmaaikel / css-to-inline-styles
Only a Fork of -> 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.
Requires
- php: >=7.0.0
- ext-dom: *
- symfony/css-selector: ~3.0 || ~4.0 || ~5.0
- voku/simple_html_dom: ~4.5
Requires (Dev)
- phpunit/phpunit: ~6.0 || ~7.0
- 2.5.0
- 2.04
- 2.1.0
- 2.0.5
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- dev-master / 1.6.x-dev
- 1.6.37
- 1.6.36
- 1.6.35
- 1.6.34
- 1.6.33
- 1.6.32
- 1.6.31
- 1.6.30
- 1.6.29
- 1.6.28
- 1.6.27
- 1.6.26
- 1.6.25
- 1.6.24
- 1.6.23
- 1.6.22
- 1.6.21
- 1.6.20
- 1.6.19
- 1.6.18
- 1.6.17
- 1.6.16
- 1.6.15
- 1.6.14
- 1.6.13
- 1.6.12
- 1.6.11
- 1.6.10
- 1.6.9
- 1.6.8
- 1.6.7
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.6
This package is auto-updated.
Last update: 2025-03-11 22:19:49 UTC
README
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.
About
PHP CssToInlineStyles is a class to convert HTML into HTML with inline styles.
Installation
The recommended installation way is through Composer.
$ composer require Mmaaikel/css-to-inline-styles
Example
use mmaaikel\CssToInlineStyles\CssToInlineStyles;
// Convert HTML + CSS to HTML with inlined CSS
$cssToInlineStyles= new CssToInlineStyles();
$cssToInlineStyles->setHTML($html);
$cssToInlineStyles->setCSS($css);
$html = $cssToInlineStyles->convert();
// Or use inline-styles blocks from the HTML as CSS
$cssToInlineStyles = new CssToInlineStyles($html);
$cssToInlineStyles->setUseInlineStylesBlock(true);
$html = $cssToInlineStyles->convert();
// Or use linked files from the HTML as CSS
$cssToInlineStyles = new CssToInlineStyles($html);
$cssToInlineStyles->setLoadCSSFromHTML(true);
$html = $cssToInlineStyles->convert(false, 0, __DIR__ . '/../tests/');
Documentation
The following properties exists and have set methods available:
Property | Default | Description |
---|---|---|
cleanup | false | Should the generated HTML be cleaned? |
useInlineStylesBlock | false | Use inline-styles block as CSS. |
stripOriginalStyleTags | false | Strip original style tags. |
excludeMediaQueries | true | Exclude media queries from extra "css" and keep media queries for inline-styles blocks. |
excludeConditionalInlineStylesBlock | true | Exclude conditional inline-style blocks. |
Warning
Also if the default is cleanup === false
, you maybe need to use this feature, because Outlook has some special features where the inline-CSS will be ignored and it will fallback to use only the CSS-Class- or ID-properties.
$cssToInlineStyles->setCleanup(true);
Known issues
- no support for pseudo selectors