--- id: premailer version: "3.10.0" license: Python license_treatment: permissive maintenance: dormant --- # premailer — Turns CSS blocks into style attributes License: permissive · Maintenance: dormant · Downloads: 5.0M/mo ## What it is and what it does Premailer is a Python library that transforms HTML documents by inlining CSS styles into HTML element attributes. It parses HTML, extracts CSS from style blocks and external stylesheets, and rewrites the DOM to apply those styles as inline style attributes—a requirement for most email clients, which strip out style tags for security reasons. The package handles relative URL rewriting (converting relative links to absolute ones using a base URL), CSS selector parsing via cssutils and cssselect, and HTML parsing via lxml. It offers both a simple transform() function for basic use and a full Premailer class for advanced configuration. It can preserve or strip certain CSS features (pseudoclasses, !important declarations, class attributes) and supports command-line usage for batch processing. Use it for: - Prepare HTML newsletters and transactional emails for delivery by inlining all styles before sending. - Convert relative URLs in email templates to absolute URLs using a base_url parameter. - Strip !important declarations and pseudoclasses from CSS to ensure compatibility with email clients. - Process HTML templates from a file or stdin via the command-line interface for CI/CD pipelines. - Preserve specific CSS or links (e.g., handlebar syntax, cid: attachments) while inlining other styles. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Converts CSS style blocks into inline style attributes on HTML elements, making HTML suitable for email clients that don't support style tags. Yes, if you are building email systems. Premailer solves a real, specific problem—email clients require inline styles—and does it reliably. The dormant maintenance is a minor concern given the stable classifier and zero known vulnerabilities, but verify that its CSS and HTML parsing behavior still meets your email client compatibility needs before adopting it for new projects. ## Install pip install premailer uv add premailer poetry add premailer ## Installing premailer Before you install: Low friction: pure Python wheel with five straightforward runtime dependencies (lxml, cssselect, cssutils, requests, cachetools). Maintenance is dormant—last release was 2021-08-02 and last commit 2023-12-16—but the package is marked Production/Stable and has no known vulnerabilities. License in practice: Licensed under the Python Software Foundation License, a permissive license. No restrictions on use, modification, or distribution in commercial or private projects. Quickstart: pip install premailer from premailer import transform html = '
Hello
' result = transform(html) print(result) By default, premailer attempts to download external stylesheets over the network; use allow_network=False to prevent this if needed. Verify before relying: - Whether the dormant maintenance status (last release 2021-08-02) affects compatibility with modern email clients or CSS specifications. - Performance characteristics when processing large HTML documents or many external stylesheets. ## Package facts - License: Python (permissive) - Python support: unspecified - Install friction: low - Maintenance: dormant - Downloads: 5.0M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags css to inline styles, html email preprocessing, style tag inlining, email html transformation, css inlining for email, html style attributes, email client compatibility, email-processing, html-transformation, css-inlining [View on SkillFed](https://skillfed.io/packages/premailer) · [View on PyPI](https://pypi.org/project/premailer/)