Format and beautify JavaScript
Beautify minified or messy JavaScript and JSON-like code with your choice of indentation and brace style.
0 / 1,000,000 characters · Updates as you type.
Minified JavaScript is a single line with every space removed, and code pasted from a chat, a PDF or an old project is often indented in several different styles at once. Either way, reading it is slow. This formatter lays the code out consistently: one statement per line, blocks indented by the width you choose, spaces around operators and after commas, and long chains broken where it helps.
You can pick two spaces, four spaces or tabs, and the brace style your team uses: braces on the same line as the if or function, braces on their own line (Allman style), or the variant that puts else on a new line. Blank lines from the input can be kept (up to two in a row) so the original grouping survives, and long lines can be wrapped at 80 to 120 characters. Modern syntax such as arrow functions, classes, template literals, async/await, optional chaining and spread is handled.
Formatting is done by js-beautify (MIT), about 17 KB compressed and loaded only when you format something here. It is a beautifier, not a compiler: it does not check that your code runs, it cannot rename minified variables back to their original names, and it does not reorder anything. For source that was bundled, a source map from the original build is the only way to recover real names. The code never leaves your browser.
How to use it
- Paste the JavaScript (minified or not) into the input.
- Choose the indentation and brace style.
- Read the formatted code as you type; turn blank-line preservation off for very compact output.
- Copy the result or download formatted.js.
Frequently asked questions
Can it restore original variable names from minified code?
No. Minifiers replace names like totalPrice with a or b, and that information is gone. Only the source map from the original build can map them back.
Does it support TypeScript or JSX?
Simple TypeScript and JSX usually format acceptably, but type annotations and JSX are not fully understood. Use your editor's formatter (for example Prettier) for those projects.
Will formatting break my code?
It only changes whitespace and line breaks, which JavaScript ignores in almost every case. Automatic semicolon insertion can matter in unusual code without semicolons, so run your tests if you format production code.
Does it check for errors?
No. It formats what you paste, even if it would not run. Use your browser console or a linter to find syntax errors.
Can I format JSON with it?
Yes, but the JSON formatter is better for JSON: it validates the input and reports the exact position of errors.
Related tools
- Format, beautify or minify JSONPretty-print or minify JSON with 2-space, 4-space or tab indentation and optional key sorting.
- Format and beautify HTMLBeautify minified or messy HTML with consistent indentation, including inline CSS and JavaScript.
- Format and beautify CSSUnminify and beautify CSS: one declaration per line, clean indentation, readable media queries.
- Minify JSONStrip every unnecessary space and line break from JSON and see how many bytes you saved.
- Test a regular expressionTest a JavaScript regular expression against text with highlighted matches, capture groups and a timeout guard.
- Format, minify and check XMLPretty-print or minify XML and check that it is well-formed, with the line and column of any error.