CSS Formatter

Runs 100% in your browser

Format and beautify CSS locally with configurable indentation, brace style, property sorting, comment removal, blank-line control, and lint diagnostics. Copy, download, and history — no upload.

CSS Input

Formatted Output

Input
Output
Delta
Rules
Declarations
Comments

Diagnostics

Recent Formatting Sessions
No formatting history yet
?? All CSS processing happens in your browser — no server, no upload, no account required. Press Ctrl+Enter to format.

Frequently asked questions

A CSS Formatter (also called a CSS Beautifier or CSS Pretty Printer) takes minified, inline, or inconsistently spaced CSS and reformats it with consistent indentation, line breaks, and spacing to improve readability and maintainability. It is the opposite of a CSS Minifier — a formatter adds structure for developers while a minifier removes it for delivery.

Paste your CSS into the input panel or open a local .css file. Choose your indentation style (2 spaces, 4 spaces, or tab), configure brace and semicolon options, then click Format CSS or enable Live mode. Review the formatted output, inspect the diagnostics panel, and copy or download the result.

Yes. The formatter supports 2-space indentation (the most common web standard), 4-space indentation (common in PHP and Python communities), and tab indentation (preferred by developers who use accessibility tools or want configurable tab-stop widths in their editor). The indent setting applies to all nested blocks including @media, @keyframes, @supports, and other at-rules.

By default the opening brace is placed at the end of the selector line: .selector {. Enabling the opening brace on new line option moves it to the start of the next line in the Allman/BSD brace style: .selector followed by { on its own line. Some teams prefer Allman style for legibility, while most CSS projects use the default K&R style with the brace inline.

When enabled, all CSS declarations within each rule block are sorted alphabetically by property name. Vendor-prefixed properties sort as if the prefix were stripped, so -webkit-transform and -moz-transform sort near transform. Sorted properties help with diff reviews and code reviews but can change visual reading order — review animated or cascade-order-sensitive declarations after sorting.

Yes. Check Remove comments to strip all block comments from the output. Check Preserve /*! comments to keep important comments (those starting with /*!) even when Remove comments is on. Important comments are conventionally used for license headers, build-tool directives, and attribution notices that should not be discarded.

Yes by default. A blank line is inserted after each closing brace at the root level to separate rule blocks visually. You can uncheck Blank line between rules to produce compact but still formatted output without the extra spacing. Nested blocks inside @media or other at-rules are not affected by this setting.

The diagnostics panel checks for: unclosed block comments that would prevent CSS parsing, mismatched brace counts (different numbers of opening and closing braces), duplicate selectors that may indicate copy-paste errors or redundant rules, overuse of !important (more than five occurrences), and possible missing semicolons before closing braces. These are heuristic checks — review findings before making changes.

No. Formatting and validation are separate concerns. The formatter produces consistently structured output from whatever CSS it receives. Syntax errors, invalid property names, unsupported values, and compatibility issues are not detected beyond the basic lint heuristics. Use a dedicated CSS validator such as the W3C CSS Validator or a project linter like Stylelint for comprehensive validation.

Yes. The formatter handles at-rule blocks including @media, @keyframes, @supports, @layer, @font-face, and @import. Nested blocks inside @media rules are indented to the correct depth. @keyframes percentage stops are formatted as regular rule blocks.

Yes. The formatter is designed to take minified CSS — a single long line with no whitespace — and expand it into a readable multi-line form. This is useful for inspecting third-party stylesheets, debugging build output, or reviewing vendor CSS before modifying it.

When Live mode is enabled, the output panel updates automatically on every keystroke in the input. This is useful for rapid iteration but can be slow on very large stylesheets. For large inputs, disable Live mode and click Format CSS explicitly to format only when you are ready.

Yes. Click Open .css to select a local CSS file. The file is read by the browser's FileReader API entirely in memory. No data is sent to any server. This allows you to format private stylesheets, company design systems, or confidential project CSS without any data leaving your device.

The formatter works on plain CSS including the output generated by SASS, LESS, PostCSS, or Tailwind. It does not parse preprocessor-specific syntax such as SASS variables ($var), LESS mixins, or nesting before CSS Nesting support is compiled. For preprocessor source files use a formatter that understands the preprocessor syntax, then use this tool on the compiled CSS output.

CSS Nesting (the native CSS Nesting spec, not SCSS) uses the same brace and selector syntax as regular CSS, so the formatter handles it correctly — each nested rule is indented one additional level inside its parent block. The formatter does not validate whether the nesting syntax is valid in target browsers.

Yes. CSS custom properties (--my-variable: value) are treated as standard declarations and are reformatted like any other property-value pair. The property name and value are preserved exactly. Custom properties in @property rules are also preserved.

Yes. Click Copy CSS to copy the entire formatted output to the clipboard using the Clipboard API. On older browsers a textarea-select fallback is used. The copied text includes trailing newlines consistent with the formatter output.

Yes. Click the download button to save the formatted output as formatted.css. The file is created as a Blob URL in the browser and no server is involved. You can rename the file after downloading.

The recent formatting sessions panel logs up to eight recent formatting operations. Each entry shows the first line of the input and the timestamp. Click any entry to reload that CSS into the input for further editing or reformatting. History is in-memory only and clears when you close or reload the page.

No. Open DevTools Network tab while using the tool. You will see zero outbound requests triggered by formatting. The entire tool is implemented in vanilla JavaScript running in your browser with no external dependencies. Nothing is uploaded.

What is CSS Formatter?

A CSS Formatter (also called a CSS Beautifier or CSS Pretty Printer) takes minified, compressed, or inconsistently indented CSS and reformats it into readable, consistently structured source code. It is the essential counterpart to a CSS Minifier — while minification removes formatting for delivery file size, formatting restores it for developer readability, code review, debugging, and version-control diffs.

CSS Formatting Options That Matter

Indentation is the most visible formatting choice. Two-space indentation is the most common convention in web projects and matches most ESLint, Prettier, and Stylelint defaults. Four-space indentation is common in PHP, Python, and back-end template projects. Tab indentation is preferred by developers who use screen readers or want configurable tab-stop widths without editing files. The setting applies consistently to every nesting level including @media, @keyframes, @supports, @layer, and @font-face blocks.

Brace style determines where the opening brace appears. K&R style (default) keeps the brace on the same line as the selector: .selector { — this is the universal CSS convention and matches every linting tool default. Allman style places the brace on its own line, which some developers prefer for visual clarity. Both are valid CSS; choose based on your project's style guide.

Property sorting alphabetises all declarations within each rule block, treating vendor prefixes as transparent so -webkit-transform and -moz-transform sort near transform. Sorted declarations reduce diff noise, help reviewers spot duplicates, and are required by some team style guides. However, sorting changes visual grouping — review animated properties and cascade-order-dependent declarations carefully after enabling it.

Comment handling gives you two independent controls. Remove comments strips all block comments to reduce verbosity in minified-to-readable workflows. Preserve /*! comments keeps important comments — those beginning with the /*! marker — even when comment removal is on. Important comments conventionally carry license headers, build-tool directives, and attribution notices that should not be discarded.

CSS Lint Checks and Diagnostics

The formatter's diagnostics panel runs heuristic checks on the input CSS before formatting. Unclosed block comments are reported because a missing */ causes every subsequent rule to be treated as comment content, producing an invisible parse failure in all browsers. Mismatched brace counts catch copy-paste errors or incomplete refactors where extra or missing braces would break the cascade. Duplicate selectors flag potential redundancy. Overuse of !important (more than five instances) is flagged because excessive !important usage is a common sign of specificity issues that should be resolved with proper selector architecture. A possible missing semicolon before } is detected when the last declaration in a block appears to lack its terminating semicolon.

These checks are heuristic and intentionally conservative — they do not replace a full CSS validator or Stylelint configuration. For comprehensive validation including property name checks, vendor prefix requirements, compatibility grids, and cascade analysis, use a dedicated CSS linter in your build pipeline.

Common use cases

  • Converting minified third-party or vendor CSS to readable formatted source for debugging and review
  • Reformatting team CSS that has accumulated inconsistent indentation, spacing, and brace styles across multiple contributors
  • Preparing CSS for a pull request or code review by normalising style so reviewers focus on logic rather than formatting
  • Sorting CSS declarations alphabetically to reduce diff noise and match a project-wide style guide requirement
  • Detecting mismatched braces, duplicate selectors, and !important overuse before committing a stylesheet
  • Reformatting @keyframes, @media, and other at-rule blocks that have been manually compressed for version-control commits

Why use ToolsSonic's CSS Formatter?

ToolsSonic's CSS Formatter supports 2-space, 4-space, and tab indentation, K&R and Allman brace styles, property sorting, comment removal with /*! preservation, blank-line control, and live mode — plus lint diagnostics for unclosed comments, brace mismatches, duplicate selectors, and !important overuse. All processing is client-side with no upload.

vs. CSS Beautify (freeformatter.com/css-beautifier): FreeFormatter requires a form submission and a page reload per format operation and does not offer property sorting, lint diagnostics, or a session history panel. ToolsSonic updates on every keystroke in live mode and stores the last eight sessions locally.

vs. Code Beautify (codebeautify.org/css-beautify-minify): Code Beautify has been observed to damage calc() expressions and data URL content — similar to the documented issue with its CSS Minifier. ToolsSonic's tokenizer protects all url() calls and quoted strings before processing, preventing data URI corruption and calc() breakage.

vs. Prettier (CLI): Prettier is the gold standard for automated code formatting in project builds. ToolsSonic is not a replacement for Prettier in a build pipeline. It is a fast browser-based tool for one-off formatting, inspection, and debugging without requiring Node.js, a project configuration, or command-line access.

Privacy guarantee: Open DevTools → Network tab. Paste any CSS. Click Format CSS. You will see zero outbound requests. Nothing is uploaded.

CSS Formatting Options Reference

OptionValuesEffect
Indent2 spaces / 4 spaces / TabApplied at every nesting level for all rule and at-rule blocks
Opening brace on new lineOff (K&R) / On (Allman)Off: .sel { inline. On: .sel { on next line
Semicolon after last declarationOn (default) / OffAdds ; after the last property-value pair in each block
Sort properties A–ZOff (default) / OnSorts declarations alphabetically, strips vendor prefix for sort key
Remove commentsOff (default) / OnStrips all block comments from output
Preserve /*! commentsOn (default) / OffKeeps important comments even when Remove comments is on
Blank line between rulesOn (default) / OffInserts blank line after each closing } at root level

ToolsSonic CSS Formatter vs Competitors

FeatureToolsSonicFreeFormatterCode BeautifyPrettier (CLI)
Real-time / live mode❌ page reload❌ button✅ watch mode
Property sort option
Lint diagnostics✅ 5 checks
calc() / url() safe✅ tokenizer protects⚠️ known damage
Session history✅ 8 entries
No upload / fully local❌ server-rendered❌ server-rendered✅ CLI
Install required❌ none❌ none❌ none✅ Node.js + npm
100% private — runs in your browser Instant — no server round-trip Free forever — no account needed

CSS Minifier

Editor's choice

Minify CSS locally with protected strings, URLs, data URLs, custom properties, calc expressions, safe color and zero-unit reductions, byte savings, diagnostics, history, copy, and download.

HTML Formatter

Editor's choice

Beautify HTML locally with configurable indentation, attribute wrapping, raw-text preservation, document outline, live mode, and instant download — all private, no upload.

HTML Beautifier

Editor's choice

Beautify dense or compressed HTML locally with indentation, line wrapping, attribute formatting, raw-text preservation, heading outline, live mode, and download — all private, no upload.

JS Minifier

Editor's choice

Minify JavaScript locally with token-aware protection for strings, templates, regex literals, comments, operators, and syntax-sensitive line breaks. Compare bytes, copy, and download privately.

HTML Minifier

Editor's choice

Minify HTML locally by removing ordinary comments and unnecessary inter-tag whitespace while protecting pre, textarea, script, and style content. Compare byte savings, copy, and download the result privately.

HTML Editor

Editor's choice

Edit HTML with a live preview — synchronized source editor, WYSIWYG visual pane, sandboxed preview, 5 starter templates, format, minify, validate, find/replace, file import, and download. 100% in your browser.