skillfed

css-inline

High-performance library for inlining CSS into HTML 'style' attributes

css-inline v0.21.1 3.1M downloads/30d#2,730 on PyPI315
Permissive license Active released

What it is and what it does

css_inline is a high-performance library that transforms CSS rules from style and link tags into inline style attributes on HTML elements. It's built on Mozilla's Servo project components and is designed for scenarios like preparing HTML emails or embedding HTML into third-party web pages where external stylesheets cannot be used. The library handles CSS resolution, can load external stylesheets (including from the filesystem), and optionally caches them to reduce repeated network requests.

It offers both simple one-shot functions (inline, inline_fragment) and batch processing (inline_many, inline_many_fragments) for concurrent document processing. Configuration options let you control whether to keep or remove style/link tags, minify CSS, apply width/height attributes, and skip inlining for specific elements via data attributes. It supports HTML5 and CSS3, works on Linux, Windows, macOS, and in the browser via PyOdide, and is tested on CPython 3.10–3.14 and PyPy 3.11.

Use it for:

  • Prepare HTML emails by inlining all CSS so styles render correctly in email clients that strip external stylesheets.
  • Embed HTML snippets into third-party web pages where external CSS links are not allowed or would conflict.
  • Batch-process multiple HTML documents concurrently to improve throughput when generating many styled documents.
  • Generate responsive emails by keeping @media queries in style tags while inlining base styles into elements.
  • Load and cache stylesheets from the filesystem or remote URLs to avoid repeated network requests during bulk HTML generation.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Inlines CSS from style and link tags directly into HTML element style attributes, transforming external stylesheets into inline styles suitable for email and embedded HTML contexts.

Yes. The package is actively maintained, has no known vulnerabilities, supports current Python versions (3.10+), and solves a specific and common problem (CSS inlining for email and embedded HTML) with a permissive license. Medium install friction is acceptable given the availability of pre-built wheels for most platforms. Suitable for production email systems and HTML embedding workflows.

Install

css-inline on PyPI

pip

pip install css-inline

uv

uv add css-inline

poetry

poetry add css-inline

Installing css-inline

Before you install

Medium install friction due to compiled Rust bindings, but pre-built wheels cover most common platforms (Linux, macOS, Windows, WebAssembly). Requires Rust 1.65+ only if building from source on unsupported platforms. Active maintenance with a release 6 days ago.

License in practice

Licensed under MIT (permissive), allowing unrestricted use, modification, and distribution in both open-source and proprietary projects.

Quickstart

pip install css_inline

import css_inline

HTML = "<style>h1 { color: blue; }</style><h1>Text</h1>"
inlined = css_inline.inline(HTML)

Requires Python 3.10 or higher; pre-built wheels available for most platforms, but Rust 1.65+ needed to build from source on unsupported architectures.

Verify before relying

  • Whether the 10-500x performance claim versus alternatives is independently verified or measured under specific conditions.
  • Whether stylesheet caching actually reduces network overhead in typical email-generation workflows.
  • Whether parallel processing via inline_many provides measurable speedup on typical multicore systems.

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.10)
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance actively maintained — 6 days since the last release
Last repo commit
First released
Downloads 3,143,174/month — #2,730 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: css_inline-0.21.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl; css_inline-0.21.1-cp310-abi3-macosx_10_12_x86_64.whl; css_inline-0.21.1-cp310-abi3-manylinux_2_12_i686.manylinux2010_i686.whl; css_inline-0.21.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; css_inline-0.21.1-cp310-abi3-manylinux_2_24_aarch64.whl; css_inline-0.21.1-cp310-abi3-manylinux_2_24_armv7l.whl; css_inline-0.21.1-cp310-abi3-musllinux_1_2_aarch64.whl; css_inline-0.21.1-cp310-abi3-musllinux_1_2_armv7l.whl; css_inline-0.21.1-cp310-abi3-musllinux_1_2_x86_64.whl; css_inline-0.21.1-cp310-abi3-pyemscripten_2025_0_wasm32.whl; css_inline-0.21.1-cp310-abi3-win32.whl; css_inline-0.21.1-cp310-abi3-win_amd64.whl; css_inline-0.21.1-pp311-pypy311_pp73-macosx_10_12_x86_64.whl; css_inline-0.21.1-pp311-pypy311_pp73-manylinux_2_24_aarch64.whl; css_inline-0.21.1-pp311-pypy311_pp73-manylinux_2_24_x86_64.whl

Keywords: css, html, email, stylesheet, inlining

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyProgramming Language :: Rust

Tags

css inlining for htmlinline css into htmlemail html css inliningstyle attribute generationcss to inline styleshtml email preparationstylesheet inlining tool
email-htmlcss-processing

More HTML packages