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 cssbeautifierVerified import paths — ran on the pinned version, not inferred.
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.
Ensure you are using `cssbeautifier` version 1.12.0 or newer. If issues persist, try installing `jsbeautifier` explicitly first: `pip install jsbeautifier cssbeautifier`.
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.
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.
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.