{"id":23901491,"url":"https://github.com/projectwallace/format-css","last_synced_at":"2026-05-16T20:07:51.352Z","repository":{"id":173435414,"uuid":"645682019","full_name":"projectwallace/format-css","owner":"projectwallace","description":"Fast, small, zero-config library to format CSS using basic rules.","archived":false,"fork":false,"pushed_at":"2026-05-13T14:31:12.000Z","size":1067,"stargazers_count":18,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-13T14:39:13.788Z","etag":null,"topics":["css","formatter","prettier","pretty-print"],"latest_commit_sha":null,"homepage":"https://www.projectwallace.com/blog/tiny-css-formatter","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/projectwallace.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-05-26T07:43:19.000Z","updated_at":"2026-05-13T14:00:19.000Z","dependencies_parsed_at":"2026-02-10T20:00:23.622Z","dependency_job_id":null,"html_url":"https://github.com/projectwallace/format-css","commit_stats":{"total_commits":59,"total_committers":2,"mean_commits":29.5,"dds":"0.47457627118644063","last_synced_commit":"b2e4548ca9481c4203e1671b0503a009f2b42c44"},"previous_names":["projectwallace/format-css"],"tags_count":43,"template":false,"template_full_name":null,"purl":"pkg:github/projectwallace/format-css","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectwallace%2Fformat-css","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectwallace%2Fformat-css/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectwallace%2Fformat-css/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectwallace%2Fformat-css/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/projectwallace","download_url":"https://codeload.github.com/projectwallace/format-css/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectwallace%2Fformat-css/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33117350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T18:38:32.183Z","status":"ssl_error","status_checked_at":"2026-05-16T18:38:29.903Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","formatter","prettier","pretty-print"],"created_at":"2025-01-04T21:20:49.579Z","updated_at":"2026-05-16T20:07:51.339Z","avatar_url":"https://github.com/projectwallace.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# format-css\n\nFast, small, zero-config library to format CSS with basic [rules](#formatting-rules). The design goal is to format CSS in a way that makes it easy to inspect. Bundle size and runtime speed are more important than versatility and extensibility.\n\n## Example output\n\n\u003c!-- prettier-ignore --\u003e\n```css\n/* TURN THIS: */\n\n@layer base.normalize{@media (dynamic-range:high) or (color-gamut:p3){@supports (color:color(display-p3 0 0 0)){:where(html){--link:color(display-p3 .1 .4 1);--link-visited:color(display-p3 .6 .2 1)}}}}@layer base.normalize{:where(html) :where(dialog){background-color:var(--surface-1)}}\n\n/* INTO THIS: */\n\n@layer base.normalize {\n\t@media (dynamic-range: high) or (color-gamut: p3) {\n\t\t@supports (color: color(display-p3 0 0 0)) {\n\t\t\t:where(html) {\n\t\t\t\t--link: color(display-p3 .1 .4 1);\n\t\t\t\t--link-visited: color(display-p3 .6 .2 1);\n\t\t\t}\n\t\t}\n\t}\n}\n\n@layer base.normalize {\n\t:where(html) :where(dialog) {\n\t\tbackground-color: var(--surface-1);\n\t}\n}\n\n/* AND BACK AGAIN! */\n```\n\n## Installation\n\n```\nnpm install @projectwallace/format-css\n```\n\n## Usage\n\n```js\nimport { format } from '@projectwallace/format-css'\n\nlet old_css = '/* Your old CSS here */'\nlet new_css = format(old_css)\n```\n\nNeed more examples?\n\n- [StackBlitz example using CommonJS](https://stackblitz.com/edit/stackblitz-starters-phchci?file=index.js)\n- [StackBlitz example using ES Modules](https://stackblitz.com/edit/stackblitz-starters-hrhsed?file=index.js)\n\n### Partial formatters\n\nThe package also exports lower-level formatters for individual CSS constructs:\n\n```js\nimport {\n\tformat_value,\n\tformat_declaration,\n\tformat_selector,\n\tformat_atrule_prelude,\n} from '@projectwallace/format-css'\n\n// Format a CSS value (e.g. the right-hand side of a declaration)\nformat_value(node.value)\n\n// Format a single CSS declaration (property + value)\nformat_declaration(node)\n\n// Format a single CSS selector\nformat_selector(node)\n\n// Format an at-rule prelude string (e.g. the query part of @media)\nformat_atrule_prelude(node.prelude.text)\n```\n\nAll of these accept the same options as `format()`. However, `tab_size` has no effect on them since they do not produce indented output.\n\n```js\nformat_declaration(node, { minify: true })\nformat_selector(node, { minify: true })\n```\n\n## Formatting rules\n\n1. Every **AtRule** starts on a new line\n1. Every **Rule** starts on a new line\n1. Every **Selector** starts on a new line\n1. A comma is placed after every **Selector** that’s not the last in the **SelectorList**\n1. Every **Block** is indented with 1 tab more than the previous indentation level\n1. Every **Declaration** starts on a new line\n1. Every **Declaration** ends with a semicolon (;)\n1. An empty line is placed after a **Block** unless it’s the last in the surrounding **Block**\n1. Multiline tokens like **Selectors, Values, etc.** are rendered on a single line\n1. Unknown syntax is rendered as-is, with multi-line formatting kept intact\n\n## Options\n\n### Minify CSS\n\nThis package also exposes a minifier function since minifying CSS follows many of the same rules as formatting.\n\n```js\nimport { format, minify } from '@projectwallace/format-css'\n\nlet minified = minify('a {}')\n\n// which is an alias for\n\nlet formatted_mini = format('a {}', { minify: true })\n```\n\n### Tab size\n\nFor cases where you cannot control the tab size with CSS there is an option to override the default tabbed indentation with N spaces.\n\n```js\nimport { format } from '@projectwallace/format-css'\n\nlet formatted = format('a { color: red; }', {\n\ttab_size: 2,\n})\n```\n\n## CLI\n\nThis library also ships a CLI tools that's a small wrapper around the library.\n\n```\nUSAGE\n  format-css [options] [file...]\n  cat styles.css | format-css [options]\n\nOPTIONS\n  --minify            Minify the CSS output\n  --tab-size=\u003cn\u003e      Use N spaces for indentation instead of tabs\n  --help, -h          Show this help\n\nEXAMPLES\n  # Format a file\n  format-css styles.css\n\n  # Format with 2-space indentation\n  format-css styles.css --tab-size=2\n\n  # Minify\n  format-css styles.css --minify\n\n  # Via pipe\n  cat styles.css | format-css\n```\n\n## Related projects\n\n- [Format CSS online](https://www.projectwallace.com/prettify-css) - See this formatter in action online!\n- [Minify CSS online](https://www.projectwallace.com/minify-css) - See this minifier in action online!\n- [CSS Analyzer](https://github.com/projectwallace/css-analyzer) - The best CSS analyzer that powers all analysis on [projectwallace.com](https://www.projectwallace.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectwallace%2Fformat-css","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprojectwallace%2Fformat-css","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectwallace%2Fformat-css/lists"}