JavaScript Code Formatter
Format and beautify messy or minified JavaScript — re-indent by brace depth, normalize spacing and quotes, pick 1TBS or Allman braces, and control semicolons and trailing commas. Runs entirely in your browser.
Input
Style Options
Soft target for line length. Long object literals and arrays are broken up to fit.
Output
Guides
Paste minified, one-line, or just plain messy JavaScript and get clean, readable, consistently indented code back instantly. The JavaScript Code Formatter re-indents your source by brace depth, normalizes the spacing around operators and punctuation, and lets you dial in the exact style you want — all in your browser, with nothing sent to a server.
What it does
The formatter is built on a JavaScript-aware tokenizer, so it understands the difference between real code and the text inside strings, template literals, regular expressions, and comments. A brace that lives inside a string will never throw off your indentation, and quotes inside a comment are left untouched. On top of that it re-emits your code line by line with structural newlines and proper indentation, then applies a set of cosmetic passes for semicolons, trailing commas, and long-line wrapping.
How to use it
- Paste your JavaScript into the input box, or click Try an example to load a messy snippet.
- Adjust the style options to taste.
- The formatted result appears on the right, ready to Copy or Download as a
.jsfile.
Formatting runs automatically as you type or change an option.
Style options
- Indentation — 2 spaces, 4 spaces, or tabs.
- Quotes — normalize all string literals to single or double quotes, or preserve what you wrote. Conversion is escape-aware, so
"it's"and'say \"hi\"'are handled safely. - Semicolons — always add missing statement semicolons, strip them (ASI style), or preserve.
- Brace style — Same line (1TBS) keeps the opening brace at the end of the line; Next line (Allman) puts it on its own line.
- Trailing commas — none, ES5 (objects and arrays only), or all (including function arguments).
- Print width — a soft target for line length; long object literals, arrays, and argument lists are broken onto multiple lines to fit.
- Collapse blank lines — squash runs of two or more blank lines into one.
Does it work on minified code?
Yes. Single-line, minified bundles are exactly what it is designed for — it splits statements onto their own lines, restores indentation, and spaces everything out.
Will it change what my code does?
No. It only reformats whitespace, quotes, semicolons, and commas — it never rewrites logic, renames anything, or removes code. If it encounters something it cannot parse cleanly, it returns your input unchanged rather than mangling it.
Is my code private?
Completely. All formatting happens locally in your browser using a self-contained engine — no third-party libraries and no network requests. Your code never leaves your device.
JSON, TypeScript, or JSX?
This tool targets plain JavaScript. It will tidy up JSON-like object literals, but for JSON specifically a dedicated JSON formatter gives better results. TypeScript type annotations and JSX are mostly preserved but not fully understood.