PHP Classes


Recommend this page to a friend!
  Classes of Lars Moelleken   PHP CSS to Inline Styles   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP CSS to Inline Styles
Convert CSS styles into HTML attribute values
Author: By
Last change: Update
Date: 4 years ago
Size: 3,756 bytes


Class file image Download

Build Status Coverage Status Scrutinizer Code Quality Codacy Badge SensioLabsInsight Latest Stable Version Total Downloads Latest Unstable Version PHP 7 ready License

CssToInlineStyles class

WARNING: this is only a Extended-Fork of ""

> 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.


PHP CssToInlineStyles is a class to convert HTML into HTML with inline styles.


The recommended installation way is through Composer.

$ composer require voku/css-to-inline-styles


use voku\CssToInlineStyles\CssToInlineStyles;

// Convert HTML + CSS to HTML with inlined CSS
$cssToInlineStyles= new CssToInlineStyles();
$html = $cssToInlineStyles->convert();

// Or use inline-styles blocks from the HTML as CSS
$cssToInlineStyles = new CssToInlineStyles($html);
$html = $cssToInlineStyles->convert();

// Or use linked files from the HTML as CSS
$cssToInlineStyles = new CssToInlineStyles($html);
$html = $cssToInlineStyles->convert(false, 0, __DIR__ . '/../tests/');


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.


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.


Known issues

  • no support for pseudo selectors