Convert HTML email templates with external CSS into inline-styled HTML that renders correctly in Gmail, Outlook, and other email clients.
Automate CSS inlining in a Laravel application before sending transactional emails.
Prepare marketing email HTML for email service providers that require all styles to be inline.
UTF-8 requires a specific meta tag format, pseudo-selectors and CSS escape sequences are not supported.
When you build a web page, you typically put your visual style rules in a separate CSS file. That works fine in browsers, but email clients are a different story. Most email programs strip out or ignore external stylesheets, so your carefully designed HTML email arrives looking plain and broken. This library solves that problem. CssToInlineStyles is a PHP tool that takes your HTML and your CSS file, then merges them together by moving all the style rules directly onto the individual HTML elements as inline attributes. The result is an HTML file where every element carries its own styling, which email clients can read without needing to load any external resources. Using it is straightforward: you load your HTML content, load your CSS content, pass both into the converter, and get back the combined output. It is commonly installed through Composer, which is the standard way PHP projects bring in outside libraries. The library is used by several notable projects, including the Laravel Framework for its mail handling and the Fork CMS platform. There are some things the library does not do. It does not handle pseudo-selectors, which are CSS features like hover states or first-child rules. It also does not support CSS escape sequences, which are a specific way of writing unusual characters in CSS. Character encoding with UTF-8 can also be inconsistent unless you include a specific meta tag in the HTML head with the older http-equiv format rather than the shorter modern version. The README is brief and focused. It covers installation, a basic code example, and the known limitations. If your project involves sending HTML emails from PHP and you need the styling to survive inside email clients, this library handles that conversion step.
← tijsverkoyen on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.