How to use the Code Formatter
- 1
Paste your code into the Input pane, drop a file onto it, or press Sample to load an example. The language is detected automatically; pick one from the Language menu to override it.
- 2
Choose Beautify to pretty print the code or Minify to shrink it. Minify is available for JavaScript, CSS, HTML, JSON and SQL.
- 3
Set the style: 2 spaces, 4 spaces or tabs, a print width of 80, 100 or 120 columns, and for JavaScript and TypeScript whether to use single quotes, semicolons and trailing commas. SQL has its own dialect and keyword case options.
- 4
The result updates as you type. Syntax errors are reported with the line and column and underlined in the input.
- 5
Press Copy (or Ctrl+Shift+C) to take the result, Download to save it with the right file extension, or the arrow button to feed the output back into the input.
Features
- Beautifies JavaScript, TypeScript, HTML, CSS, SCSS, JSON and SQL with Prettier and sql-formatter, the same engines your editor uses
- Minifies JavaScript with terser, CSS with csso, and HTML, JSON and SQL with careful whitespace passes
- Detects the language from the pasted code or the opened file
- Indent, print width, quote style, semicolons and trailing commas match any project style
- Thirteen SQL dialects including MySQL, PostgreSQL, SQL Server, BigQuery and Snowflake
- Syntax errors are underlined in the editor with the exact line and column
- Shows input and output sizes and the percentage saved when minifying
- Formatters are downloaded on first use and then work offline; nothing is uploaded
Why format code
Badly indented code is hard to review and minified code is impossible to read. This tool does both jobs in one place: paste JavaScript, TypeScript, HTML, CSS, SCSS, JSON or SQL, pick Beautify to pretty print it or Minify to squeeze it down, and the result appears as you type. There is no submit button, no page reload and no upload.
Beautifying uses Prettier, the formatter most editors run on save, so the output matches what your project would produce. That matters when you paste a snippet from a pull request, a Stack Overflow answer or a production bundle and want it to look like the rest of the codebase before you read it.
Formatter versus minifier
A formatter adds whitespace for people. A minifier removes it, and more, for machines. Terser also renames local variables to single letters, drops unreachable code and folds constant expressions, which is why a minified JavaScript file can be half the size of the original even after gzip. Csso goes further than whitespace too: it merges rules with the same selector and removes overridden declarations.
The size readout in the output header shows exactly how much was saved. For HTML and SQL the saving is smaller, because those minifiers deliberately keep anything that could change meaning, such as the contents of a pre block or a quoted string.
Matching your project style
The options map directly onto Prettier settings: Indent is tabWidth and useTabs, Width is printWidth, and the three chips are singleQuote, semi and trailingComma. Set them once and they are remembered on this device. If your repository has a Prettier config, copy the values from it and the output will diff cleanly against your files.
SQL has no single style guide, so the tool exposes the two choices that cause the most arguments: the dialect, which decides which keywords and operators are recognised, and keyword case. Uppercase keywords are the conventional choice; lowercase is common in Postgres teams.
Related tasks
To tidy JSON only, the JSON Formatter adds tree and table views and key sorting. To see what a formatter changed, paste the before and after into the Text Diff Checker.
Frequently asked questions
Which formatter does this tool use?
How is the code minified?
Why can I not minify TypeScript or SCSS?
Does minifying HTML break my page?
How does language detection work?
Where do the error line and column come from?
Is my code uploaded anywhere?
Last updated .