Registry / serialization / cssbeautifier

cssbeautifier

JSON →
library2.0.3pypypi✓ verified 26d ago

A Python library for unobfuscating and beautifying CSS code, improving readability and maintainability. It is currently at version 1.15.4 and is part of the larger `js-beautify` project, with releases tied to its development cycle. The library provides programmatic access to format CSS strings or files with configurable options.

pip install cssbeautifier
INSTALL
IMPORT
SIG · CSSBEAUTIFIER
C
cssbeautifier
serializationpythonv2.0.3
Install
1.8s avg
Import
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.000s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

beautify
from cssbeautifier import beautify
import cssbeautifier

This quickstart demonstrates how to beautify a CSS string using the `cssbeautifier.beautify` function. It shows both default formatting and how to customize options like indentation size and newline rules using `cssbeautifier.default_options`. The library also supports reading from and writing to files.

import cssbeautifier ugly_css = ".container{display:flex;}.item{color:red;font-size:16px;margin:0 auto;}" # Beautify with default options pretty_css_default = cssbeautifier.beautify(ugly_css) print("--- Default Beautification ---") print(pretty_css_default) # Beautify with custom options opts = cssbeautifier.default_options() opts.indent_size = 2 opts.end_with_newline = True opts.newline_between_rules = False pretty_css_custom = cssbeautifier.beautify(ugly_css, opts) print("\n--- Custom Beautification (2-space indent, no newline between rules) ---") print(pretty_css_custom) # Example of beautifying a file (conceptual, requires a file to exist) # Assuming 'styles.min.css' exists with ugly_css content # with open('styles.min.css', 'w') as f: # f.write(ugly_css) # beautified_file_content = cssbeautifier.beautify_file('styles.min.css', opts) # print("\n--- Beautified File Content ---") # print(beautified_file_content)
cssbeautifier --version
Debug
Known issues
breakingPast versions (e.g., v1.11.0) experienced `pip install cssbeautifier` failures due to packaging issues related to the `jsbeautifier` dependency. While fixed in later releases (v1.12.0), this highlights a potential fragility in the dependency management.
fix
Ensure you are using `cssbeautifier` version 1.12.0 or newer. If issues persist, try installing `jsbeautifier` explicitly first: `pip install jsbeautifier cssbeautifier`.
affects: <1.12.0
gotchaThe Python `cssbeautifier` library is specifically designed for CSS code and *does not* support HTML beautification. Users familiar with the Node.js version of the beautifier might expect HTML support, but this functionality is not available in the Python package.
fix
For HTML beautification in Python, consider alternative libraries or use the Node.js `js-beautify` CLI/library. The `cssbeautifier` package should only be used for CSS.
affects: All versions
gotchaThe beautifier may produce unexpected results or even invalid CSS for highly complex, unconventional, or malformed CSS syntax. Historical issues include incorrect handling of `@media` queries, `@font-face` rules, nested `@-rules`, and comments with quotes, leading to extra spaces or parsing errors.
fix
Always review the output of the beautifier, especially for complex CSS. Test the beautified code to ensure it remains valid and functional. If consistent issues arise with specific CSS constructs, consider opening an issue on the project's GitHub page.
affects: All versions
gotchaWhen configuring options, the Python API uses `snake_case` for option names (e.g., `indent_size`), while the command-line interface (CLI) and some other language implementations (e.g., Node.js) typically use `kebab-case` (e.g., `--indent-size`).
fix
Refer to the Python documentation for the correct `snake_case` option names when setting `BeautifierOptions` attributes. Avoid directly translating CLI flags to Python option names without adjustment.
affects: All versions
Upgrade
Version history
2.0.3latest on PyPI · released Jun 30, 2026
Audit
Dependencies
jsbeautifierrequiredCore functionality is built upon and automatically installs `jsbeautifier` as a dependency for shared logic.
sixoptionalPython 2/3 compatibility layer, often an indirect dependency for projects supporting a broader range of Python versions.
editorconfigoptionalUsed for reading `.editorconfig` files to configure formatting options.
Agent activity
5 hits · last 30 days
node
4
Resources
cssbeautifier — pip install cssbeautifier · libregistry