Skip to content
Transform embedded and external stylesheets to style attributes on the HTML tags.
Find file
New pull request
Latest commit c0af533 @christiaan Merge pull request #39 from mailXpert/master
Possibility to not remove the styles


Build Status Scrutinizer Quality Score

InlineStyle provides an easy way to apply embedded and external stylesheets directly as inline styles on the HTML tags. This is especially targetted at mail clients which mostly dont support stylesheets but do support the style attribute for HTML tags.


Run composer.phar require inlinestyle/inlinestyle Or add the following to your composer.json file "require": { "inlinestyle/inlinestyle": "1.*" }


Use composer to download required dependencies.

Import InlineStyle

use \InlineStyle\InlineStyle;

Create a new InlineStyle object from either a HTML string or HTML file.

$htmldoc = new InlineStyle("testfiles/test.html");


$htmldoc = new InlineStyle(file_get_contents(""));

Apply the embedded and external stylesheets

First we'll have to extract the stylesheets from the document and then we have to apply them.


The second param is the base url that is used to parse the links to external stylesheets.

$htmldoc->applyStylesheet($htmldoc->extractStylesheets(null, ""));

Applying additional stylesheets

This class can also be used to apply a given css template to each processed HTML file.


Retrieving the modified HTML

After calling applyStylesheet various times the resulting HTML can be retrieved as a string using getHTML.

$html = $htmldoc->getHTML();
Something went wrong with that request. Please try again.