JavaScript Minifier
Shrink JavaScript by removing comments and whitespace, without renaming anything.
Indent and space JavaScript so it can be read.
JavaScript Formatter takes code that is minified or inconsistently written and prints it with consistent indentation, spacing around operators and one statement per line. Nesting becomes visible, which is usually all you need to start reading unfamiliar code.
The hard part of formatting JavaScript is knowing what is code and what is not. A brace inside a string is not a block. A slash might start a comment, a division, or a regular expression, and which one it is depends on what came before. Template literals can contain expressions that contain more template literals. The formatter tracks all of this, so strings, comments, regular expressions and template literals pass through byte for byte while the code around them is reshaped.
This is a formatter rather than a parser-based pretty-printer, which means it is fast, it never fails on syntax it does not recognise, and it handles modern code it has never seen. The trade-off is that deliberately unusual formatting is normalised rather than preserved. For a project with its own style rules, a dedicated tool in your build pipeline remains the better choice.
The javascript formatter is used by writers, developers, students, marketers and anyone else who needs the job done once without installing software. Common cases include:
It changes whitespace only, so behaviour is unchanged. The one thing worth checking is automatic semicolon insertion: code that relies on it is fragile already, and reformatting fragile code is a good moment to add the semicolons.
They are detected and passed through exactly as written. That matters because a brace or a slash inside a string looks identical to one in code, and a formatter that cannot tell them apart corrupts the file.
It restores whitespace and structure, not names. A minifier that renamed variables to single letters has thrown that information away, and nothing can bring it back.
Partly. Ordinary TypeScript annotations format acceptably. JSX contains markup inside expressions and is better handled by a tool that parses it properly.
No. Use a dedicated formatter in your project, configured once and run automatically. This tool is for the times you are looking at code that is not yours.
No. Formatting runs in your browser, so proprietary code stays on your device.
If the javascript formatter is not quite what you need, these other free tools solve closely related problems.
Shrink JavaScript by removing comments and whitespace, without renaming anything.
Format CSS with consistent indentation, spacing and one declaration per line.
Pretty-print HTML with consistent indentation, or collapse it back down.
Pretty-print and validate JSON, with the exact line and column of any error.
A three-pane editor with a live preview that updates as you type.