Twig CssInliner Extra

A Twig extension that inlines CSS styles into HTML for email-ready templates.

Library
Composer
vv3.26.0
230stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
46/100Fair
Development Activity36
Maintenance24
Community44
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture80
Code Quality82
Innovation66
Learning Curve88

twig/cssinliner-extra is an official Twig extension that adds an inline_css filter, converting linked or embedded CSS into inline style attributes on HTML elements. This is essential for HTML email, where most clients strip out <style> blocks and only reliably honor inline styles.

Part of the Twig ‘extra’ family of extensions, it lets you author email templates with normal CSS and a wrapping filter block, then have the styles automatically inlined at render time. Under the hood it uses tijsverkoyen/css-to-inline-styles, so you get robust, well-tested CSS inlining without leaving your Twig templates.

What You Get

  • An inline_css Twig filter for converting CSS into inline style attributes
  • Seamless integration with Twig 3 and 4 as a standard extension
  • Support for passing one or more external CSS stylesheets to inline
  • A battle-tested inlining engine via tijsverkoyen/css-to-inline-styles
  • A drop-in solution for producing email-client-compatible HTML

Common Use Cases

  • Building transactional or marketing HTML emails whose styles must be inlined
  • Rendering email templates in Symfony or standalone Twig with authored CSS
  • Ensuring consistent styling across email clients that ignore <style> tags

Under The Hood

Architecture - The package is a single small extension class, CssInlinerExtension.php, that implements Twig’s ExtensionInterface and registers the inline_css filter. The filter takes rendered HTML (and optional CSS arguments), delegates to tijsverkoyen/css-to-inline-styles to parse and apply the styles, and returns the transformed markup. Tech Stack - PHP 8.1+, Twig 3.13+/4.0, symfony/deprecation-contracts, and tijsverkoyen/css-to-inline-styles as the inlining engine. Code Quality - Maintained within the twigphp organization with a PHPUnit test suite (Tests/) and shared CI conventions across the Twig extras; the surface area is intentionally minimal and well covered. API Design - Extremely ergonomic: register the extension, then wrap HTML with {% apply inline_css %}...{% endapply %} or pipe through the inline_css filter with optional stylesheet paths. There is essentially no configuration, giving it a very shallow learning curve.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search