Skip to main content

CSS Tidy

Code Size PyPI - Version

MIT License Stars

A Python tool to tidy and format CSS files.

Features

  • CSS Formatting: Automatically format CSS code to make it more readable
  • Syntax Validation: Check CSS syntax errors
  • Batch Processing: Support batch processing of multiple CSS files
  • Custom Options: Customize indentation, line breaks, and other formatting options
  • Selector Grouping: Automatically group related CSS selectors by prefix
  • Command Line Tool: Provide simple and easy-to-use command line interface

Installation

pip install css-tidy

Usage

css-tidy [css-file-path] [options]

Command Line Usage

# Format a single CSS file
css-tidy style.css

# Format and output to a new file
css-tidy input.css -o output.css

# Batch process all CSS files in a directory
css-tidy *.css

# Use custom indentation
css-tidy style.css --indent 4

# Minify CSS
css-tidy style.css --minify

# Group selectors
css-tidy style.css --group

Command Line Options

Option Description
[Output Control]
-o, --output TEXT Output file path
-m, --minify Minify CSS output
[Formatting Options]
-i, --indent INTEGER Indentation size (default: 2)
-s, --sort Sort CSS properties
[Content Processing]
-c, --remove-comments Remove CSS comments
-g, --group Group CSS selectors by prefix
-d, --remove-duplicates Remove duplicate CSS rules
--duplicate-report Generate JSON report of duplicate rules
[Validation & Info]
--validate-only Only validate CSS, do not format
-v, --verbose Enable verbose output
--version Show version and exit
--help Show this message and exit

Python API Usage

from css_tidy import CSSFormatter

# Create formatter
formatter = CSSFormatter()

# Format CSS string
css_code = """
body{margin:0;padding:0}div{color:red}
"""
formatted_css = formatter.format(css_code)
print(formatted_css)

# Format file
formatter.format_file('input.css', 'output.css')

# Use custom options
formatter = CSSFormatter(indent_size=4, max_line_length=80)
formatted_css = formatter.format(css_code)

# Group selectors
formatter = CSSFormatter(group_selectors=True)
formatted_css = formatter.format(css_code)

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Support

If you have questions or need help, please open an issue on GitHub.

Thank you to all contributors and the open-source community for your support.

Metadata

Release files for css-tidy 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for css-tidy 0.1.7
File Size Uploaded
css_tidy-0.1.7.tar.gz 26.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for css-tidy 0.1.7
File Interpreter ABI Platform
css_tidy-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 44.4 kB

Release files / css_tidy-0.1.7.tar.gz

Download URL css_tidy-0.1.7.tar.gz
Size 26.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e713c6a5e9cda2a76adf77c18572f1fe35537f8fc0309ae877b413ce78c86fec
BLAKE2b-256 checksum
How to use checksums
2e0e6d7460677ea91a42c9884082f36f69abd0ed623232ec6e9702192433402e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Release files / css_tidy-0.1.7-py3-none-any.whl

Download URL css_tidy-0.1.7-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55465f2e5768c18cfcc2b61e83cf4bccdad50b58d83832576016dddabd99bd49
BLAKE2b-256 checksum
How to use checksums
c7b07eccf89a5a6b9c60955e4bd5e8230a3b453f1a34f04accd874480b22c6db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page