--- id: cssutils version: "2.15.0" license: LGPL-3.0-or-later license_treatment: copyleft maintenance: active --- # cssutils — A CSS Cascading Style Sheets library for Python License: copyleft · Maintenance: active · Downloads: 9.4M/mo ## What it is and what it does cssutils is a CSS parser and DOM builder for Python that reads CSS stylesheets into a structured object model you can inspect and modify programmatically. It implements the W3C DOM Level 2 Style specification and supports CSS 2.1 and parts of CSS 3, including namespaces, media queries, page rules, and custom properties. The package does not render CSS—it is purely for parsing, validation, and serialization. You use it to load a CSS string or file, walk through rules and properties, modify values or priorities, add or remove rules, and serialize the result back to text. It depends on more_itertools and encutils for utility functions. The library is mature (first released in 2007) and actively maintained, though it is not thread-safe and requires Python 3.10 or later. Use it for: - Programmatically modify CSS stylesheets in build pipelines or code generation tools. - Validate CSS syntax and property values before deployment or in linting workflows. - Extract and analyze CSS rules, selectors, and properties from stylesheets for auditing or transformation. - Build CSS dynamically by constructing rules and properties in code and serializing them to text. - Parse CSS from HTML documents or external sources and manipulate them as structured data. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. cssutils parses and builds CSS stylesheets as a DOM structure without rendering—it reads, modifies, and serializes CSS according to W3C specifications. Yes, if you need to parse, validate, or programmatically modify CSS as structured data. Install friction is low, maintenance is active, and there are no known security vulnerabilities. The copyleft license (LGPL-3.0-or-later) requires attention if you plan proprietary distribution. Not suitable for rendering or for thread-concurrent use. ## Install pip install cssutils uv add cssutils poetry add cssutils ## Installing cssutils Before you install: Low friction install with only two runtime dependencies (more_itertools, encutils). Active maintenance with a recent release; last commit 2026-04-29. Marked as Production/Stable. License in practice: Licensed under LGPL-3.0-or-later (copyleft). Derivative works and modifications must be distributed under compatible terms; proprietary use requires careful license review. Quickstart: import cssutils css = 'a { color: red; }' sheet = cssutils.parseString(css) for rule in sheet: if rule.type == rule.STYLE_RULE: rule.style['color'] = 'blue' print(sheet.cssText) Requires Python >=3.10. cssutils is known to be thread unsafe. Verify before relying: - Whether the package handles modern CSS features beyond CSS 2.1 and CSS 3 (e.g., CSS Grid, Flexbox, custom properties edge cases). - Performance characteristics when parsing large stylesheets or many rules in sequence. - Specific validation strictness for CSS properties and whether it can be configured. ## Package facts - License: LGPL-3.0-or-later (copyleft) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 9.4M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags CSS parser Python, parse CSS stylesheets, CSS DOM manipulation, CSS serialization, CSS rule parsing, stylesheet parsing library, CSS property validation, css-parsing, dom-manipulation, w3c-compliant [View on SkillFed](https://skillfed.io/packages/cssutils) · [View on PyPI](https://pypi.org/project/cssutils/)