# CSS Tidy
[](https://github.com/HenryLok0/css-tidy)

[](LICENSE)
[](https://github.com/HenryLok0/css-tidy/stargazers)
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
```bash
pip install css-tidy
```
## Usage
```
css-tidy [css-file-path] [options]
```
### Command Line Usage
```bash
# 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
```python
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](CONTRIBUTING.md) for guidelines.
---
## License
This project is licensed under the MIT License. See the [LICENSE](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.
Raw data
{
"_id": null,
"home_page": "https://github.com/henrylok/css-tidy",
"name": "css-tidy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "Henry Lok <henry.lok@example.com>",
"keywords": "css, formatting, tidy, beautify, minify",
"author": "Henry Lok",
"author_email": "Henry Lok <henry.lok@example.com>",
"download_url": "https://files.pythonhosted.org/packages/2e/0e/6d7460677ea91a42c9884082f36f69abd0ed623232ec6e9702192433402e/css_tidy-0.1.7.tar.gz",
"platform": null,
"description": "# CSS Tidy\r\n\r\n[](https://github.com/HenryLok0/css-tidy)\r\n\r\n\r\n[](LICENSE)\r\n[](https://github.com/HenryLok0/css-tidy/stargazers)\r\n\r\nA Python tool to tidy and format CSS files.\r\n\r\n## Features\r\n\r\n- **CSS Formatting**: Automatically format CSS code to make it more readable\r\n- **Syntax Validation**: Check CSS syntax errors\r\n- **Batch Processing**: Support batch processing of multiple CSS files\r\n- **Custom Options**: Customize indentation, line breaks, and other formatting options\r\n- **Selector Grouping**: Automatically group related CSS selectors by prefix\r\n- **Command Line Tool**: Provide simple and easy-to-use command line interface\r\n\r\n## Installation\r\n\r\n```bash\r\npip install css-tidy\r\n```\r\n\r\n## Usage\r\n```\r\ncss-tidy [css-file-path] [options]\r\n```\r\n\r\n### Command Line Usage\r\n\r\n```bash\r\n# Format a single CSS file\r\ncss-tidy style.css\r\n\r\n# Format and output to a new file\r\ncss-tidy input.css -o output.css\r\n\r\n# Batch process all CSS files in a directory\r\ncss-tidy *.css\r\n\r\n# Use custom indentation\r\ncss-tidy style.css --indent 4\r\n\r\n# Minify CSS\r\ncss-tidy style.css --minify\r\n\r\n# Group selectors\r\ncss-tidy style.css --group\r\n```\r\n\r\n## Command Line Options\r\n\r\n| Option | Description |\r\n|------------------------|-------------|\r\n| **[Output Control]** | |\r\n| `-o, --output TEXT` | Output file path |\r\n| `-m, --minify` | Minify CSS output |\r\n| **[Formatting Options]** | |\r\n| `-i, --indent INTEGER` | Indentation size (default: 2) |\r\n| `-s, --sort` | Sort CSS properties |\r\n| **[Content Processing]** | |\r\n| `-c, --remove-comments` | Remove CSS comments |\r\n| `-g, --group` | Group CSS selectors by prefix |\r\n| `-d, --remove-duplicates` | Remove duplicate CSS rules |\r\n| `--duplicate-report` | Generate JSON report of duplicate rules |\r\n| **[Validation & Info]** | |\r\n| `--validate-only` | Only validate CSS, do not format |\r\n| `-v, --verbose` | Enable verbose output |\r\n| `--version` | Show version and exit |\r\n| `--help` | Show this message and exit |\r\n\r\n### Python API Usage\r\n\r\n```python\r\nfrom css_tidy import CSSFormatter\r\n\r\n# Create formatter\r\nformatter = CSSFormatter()\r\n\r\n# Format CSS string\r\ncss_code = \"\"\"\r\nbody{margin:0;padding:0}div{color:red}\r\n\"\"\"\r\nformatted_css = formatter.format(css_code)\r\nprint(formatted_css)\r\n\r\n# Format file\r\nformatter.format_file('input.css', 'output.css')\r\n\r\n# Use custom options\r\nformatter = CSSFormatter(indent_size=4, max_line_length=80)\r\nformatted_css = formatter.format(css_code)\r\n\r\n# Group selectors\r\nformatter = CSSFormatter(group_selectors=True)\r\nformatted_css = formatter.format(css_code)\r\n```\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\r\n\r\n---\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\r\n\r\n---\r\n\r\n## Support\r\n\r\nIf you have questions or need help, please open an issue on GitHub.\r\n\r\nThank you to all contributors and the open-source community for your support.\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python tool to tidy and format CSS files",
"version": "0.1.7",
"project_urls": {
"Bug Tracker": "https://github.com/henrylok/css-tidy/issues",
"Documentation": "https://github.com/henrylok/css-tidy#readme",
"Homepage": "https://github.com/henrylok/css-tidy",
"Repository": "https://github.com/henrylok/css-tidy"
},
"split_keywords": [
"css",
" formatting",
" tidy",
" beautify",
" minify"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c7b07eccf89a5a6b9c60955e4bd5e8230a3b453f1a34f04accd874480b22c6db",
"md5": "895d9defd1c625a699da258a4dd9883c",
"sha256": "55465f2e5768c18cfcc2b61e83cf4bccdad50b58d83832576016dddabd99bd49"
},
"downloads": -1,
"filename": "css_tidy-0.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "895d9defd1c625a699da258a4dd9883c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 18124,
"upload_time": "2025-07-27T05:21:54",
"upload_time_iso_8601": "2025-07-27T05:21:54.659660Z",
"url": "https://files.pythonhosted.org/packages/c7/b0/7eccf89a5a6b9c60955e4bd5e8230a3b453f1a34f04accd874480b22c6db/css_tidy-0.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "2e0e6d7460677ea91a42c9884082f36f69abd0ed623232ec6e9702192433402e",
"md5": "06bffc92b20391895d81c812511e155c",
"sha256": "e713c6a5e9cda2a76adf77c18572f1fe35537f8fc0309ae877b413ce78c86fec"
},
"downloads": -1,
"filename": "css_tidy-0.1.7.tar.gz",
"has_sig": false,
"md5_digest": "06bffc92b20391895d81c812511e155c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 26269,
"upload_time": "2025-07-27T05:21:55",
"upload_time_iso_8601": "2025-07-27T05:21:55.699112Z",
"url": "https://files.pythonhosted.org/packages/2e/0e/6d7460677ea91a42c9884082f36f69abd0ed623232ec6e9702192433402e/css_tidy-0.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-27 05:21:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "henrylok",
"github_project": "css-tidy",
"github_not_found": true,
"lcname": "css-tidy"
}