explaingit

tijsverkoyen/csstoinlinestyles

5,838PHPAudience · developerComplexity · 2/5Setup · easy

TLDR

CssToInlineStyles is a PHP library that merges a CSS stylesheet into an HTML file by moving every style rule directly onto each element as an inline attribute, so HTML emails render correctly in clients that ignore external stylesheets.

Mindmap

mindmap
  root((csstoinlinestyles))
    What it does
      Merges CSS into HTML
      Inline style attributes
    Use Cases
      HTML email rendering
      Email client compat
    Setup
      Composer install
      PHP project
    Limitations
      No pseudo-selectors
      UTF-8 encoding quirks
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Convert HTML email templates with external CSS into inline-styled HTML that renders correctly in Gmail, Outlook, and other email clients.

USE CASE 2

Automate CSS inlining in a Laravel application before sending transactional emails.

USE CASE 3

Prepare marketing email HTML for email service providers that require all styles to be inline.

Tech stack

PHPComposer

Getting it running

Difficulty · easy Time to first run · 5min

UTF-8 requires a specific meta tag format, pseudo-selectors and CSS escape sequences are not supported.

In plain English

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.

Copy-paste prompts

Prompt 1
I'm building an HTML email template in PHP with a separate CSS file. Show me how to use CssToInlineStyles to merge the CSS into the HTML so it looks correct in Gmail and Outlook.
Prompt 2
I'm using the Laravel Framework and want to make sure my email templates have inline styles automatically. How does CssToInlineStyles integrate with Laravel's mail system?
Prompt 3
What limitations of CssToInlineStyles should I know before using it for my PHP email system, especially around pseudo-selectors and UTF-8 character encoding?
Prompt 4
Show me a complete PHP code example that loads an HTML file and a CSS file, runs them through CssToInlineStyles, and writes the inlined result to a new file.
Open on GitHub → Explain another repo

← tijsverkoyen on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.