skillfed

cssutils

A CSS Cascading Style Sheets library for Python

cssutils v2.15.0 9.4M downloads/30d#1,533 on PyPI92
Copyleft license LGPL-3.0-or-later Active released

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 on this page — 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

cssutils on PyPI

pip

pip install cssutils

uv

uv add cssutils

poetry

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 the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 2 — more_itertools, encutils
Maintenance actively maintained — 109 days since the last release
Last repo commit
First released
Downloads 9,443,090/month — #1,533 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: cssutils-2.15.0-py3-none-any.whl

Keywords: CSS, Cascading Style Sheets, CSSParser, DOM Level 2 Stylesheets, DOM Level 2 CSS

Development Status :: 5 - Production/StableIntended Audience :: DevelopersProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyTopic :: InternetTopic :: Software Development :: Libraries :: Python ModulesTopic :: Text Processing :: Markup :: HTML

Tags

CSS parser Pythonparse CSS stylesheetsCSS DOM manipulationCSS serializationCSS rule parsingstylesheet parsing libraryCSS property validation
css-parsingdom-manipulationw3c-compliant

More Python Modules packages