{"id":3440,"library":"css-inline","title":"css-inline: High-Performance CSS Inliner for HTML","description":"css-inline is a high-performance Python library (version 0.20.2) for inlining CSS into HTML 'style' attributes. Built on components from Mozilla's Servo project, it is significantly faster than other alternatives and is primarily designed for use cases such as preparing HTML emails or embedding HTML into third-party web pages where inline styles are a requirement. It's actively maintained with regular releases.","status":"active","version":"0.20.2","language":"en","source_language":"en","source_url":"https://github.com/Stranger6667/css-inline","tags":["css","html","email","inlining","performance","rust"],"install":[{"cmd":"pip install css-inline","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"inline","correct":"from css_inline import inline"},{"note":"For processing multiple documents concurrently for performance benefits.","symbol":"inline_many","correct":"from css_inline import inline_many"},{"note":"For custom configuration and reusing options across multiple inlining calls.","symbol":"CSSInliner","correct":"from css_inline import CSSInliner"}],"quickstart":{"code":"from css_inline import inline\n\nhtml_content = \"\"\"\n<html>\n<head>\n    <style>\n        h1 { color: blue; }\n        p { font-size: 14px; margin-bottom: 5px; }\n        .highlight { background-color: yellow; }\n        @media screen and (max-width: 600px) { p { color: #555; } }\n    </style>\n</head>\n<body>\n    <h1 class=\"highlight\">Hello, World!</h1>\n    <p>This is a paragraph.</p>\n    <p style=\"color: green;\">This paragraph has an existing inline style.</p>\n</body>\n</html>\n\"\"\"\n\ninlined_html = inline(html_content, keep_at_rules=True, keep_style_tags=True)\nprint(inlined_html)","lang":"python","description":"This example demonstrates basic CSS inlining, showing how styles from a <style> tag are applied to elements. It also illustrates how to use `keep_at_rules` and `keep_style_tags` options to prevent the default removal of `@media` queries and the original style tags."},"warnings":[{"fix":"Pass `keep_style_tags=True` and/or `keep_link_tags=True` to the `inline()` function or `CSSInliner` constructor.","message":"By default, `<style>` and `<link>` tags (including their contents) are removed from the resulting HTML after inlining. If you need to preserve them (e.g., for responsive email media queries), use the `keep_style_tags=True` or `keep_link_tags=True` options.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Pass `keep_at_rules=True` to the `inline()` function or `CSSInliner` constructor. Note that preserved `@rules` will remain in `<style>` tags if `keep_style_tags` is also `True`.","message":"At-rules (like `@media`, `@font-face`) cannot be inlined into `style` attributes and are removed by default. To preserve them (e.g., for responsive email layouts), set `keep_at_rules=True`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of this behavior for fragments. If strict fragment output is needed, post-process the output or use specialized methods if available for fragments.","message":"When inlining HTML fragments, `css-inline` automatically adds missing `<html>` and `<body>` tags to ensure the output is a valid HTML document. If you specifically need to process and return only the contents of an HTML fragment without these structural tags, consider processing and then manually stripping them, or use `inline_many_fragments` which might offer more control.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Replace `inline_with_options(html, options)` with `inline(html, **options)` or instantiate `CSSInliner(options).inline(html)`.","message":"The `inline_with_options` and `inline_many_with_options` functions were removed. Users should now pass options directly as keyword arguments to the `inline()` and `inline_many()` functions, or use the `CSSInliner` class.","severity":"breaking","affected_versions":">=0.11.0"},{"fix":"Update calls from `inline_many([html1, html2])` to `inline_many([(html1, options1), (html2, options2)])`. An empty dictionary `{}` can be used for `options` if no specific options are needed for a given HTML string.","message":"The arguments for `inline_many` and `inline_many_fragments` changed. They now expect a list of tuples `(html_string, options_dict)` instead of just `html_string` for each item. This allows specific options per document when processing in parallel.","severity":"breaking","affected_versions":">=0.16.0"},{"fix":"Understand the inherent limitations of inline CSS for these features. If dynamic or interactive styles are critical, they must be handled via client-side JavaScript or by preserving `<style>` tags.","message":"As a library for *inlining* CSS, it cannot handle pseudo-elements (`::before`, `::after`) or pseudo-classes (`:hover`, `:active`) because these CSS features cannot be represented directly as `style` attributes on HTML elements.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}