JavaScript Beautifier
Free online javascript beautifier for developers. Format and beautify JS code. Fast and private.
Embed this tool
Copy and paste the code below into your website to embed this tool for free. An attribution link to The Util Box is required.
<iframe src="https://www.theutilbox.org/embed/js-formatter" width="600" height="500" frameborder="0" style="border: none; max-width: 100%;" title="Free JavaScript Beautifier tool from The Util Box"></iframe> <!-- Free tool by The Util Box — https://www.theutilbox.org/tools/js-formatter --> <a href="https://www.theutilbox.org/tools/js-formatter">JavaScript Beautifier by The Util Box</a>
Frequently Asked Questions about JavaScript Beautifier
JavaScript Beautifier — Re-indent Minified or Messy JS
This JavaScript beautifier re-indents your code so it can be read. Paste a minified bundle, a snippet somebody sent you in a chat window, or a file with broken indentation, and the output comes back with two-space indentation, one statement per line and braces on their own lines.
It works by walking the characters of your input rather than by building a syntax tree, which makes it fast enough to run on a large bundle as you paste, and means it never rejects a file it does not understand.
The Exact Rules It Applies
Four characters drive the whole formatter, and knowing them makes its output predictable:
- Opening brace or bracket — the character is written, the indent level increases by two spaces, and a newline follows.
- Closing brace or bracket — the indent level decreases first, then the character is written on its own line at the shallower level.
- Semicolon — a newline is inserted after it, at the current indent.
- Comma — a newline is inserted after it too, at the current indent.
Runs of three or more blank lines are collapsed back down to two, and the final result is trimmed, so leading and trailing whitespace never survives into the output.
Where It Falls Short, and What to Do Instead
Because the formatter never parses JavaScript, it cannot tell code from data. That produces three predictable effects:
- Punctuation inside string literals is treated as code. A string such as
"a;b"will be split across two lines, which breaks the string and produces invalid JavaScript. The same applies to commas, braces and brackets inside quoted text. - Comments are not respected. A brace or bracket written inside a comment changes the indent level for everything that follows it.
- Every comma starts a new line. A function call with several arguments comes out as one argument per line, which is valid but often longer than the original formatting.
For real source files that need to stay byte-identical in behaviour, run them through a proper parser-based
formatter — Prettier or js-beautify — rather than this one. Use this tool for a
quick look at a bundle, a snippet or a minified file where readability now matters more than fidelity.
Related Formatters
- CSS Formatter — the same job for stylesheets, where the comma rule causes fewer problems.
- JSON Formatter — pretty-print JSON, which is parsed rather than scanned, so it is exact.
- SQL Formatter — reformat a query, with keyword-aware capitalisation.
- HTML Formatter — indent markup that has been flattened onto one line.
- Diff Checker — compare two versions of a file line by line once you have formatted them.
- Code Minifier — go the other way and strip the whitespace back out for production.
Formatting happens entirely in your browser, so proprietary or unshipped source code never leaves your machine.