JavaScript Formatter and Beautifier
WM-16Paste JavaScript to get it re-indented with each statement on its own line. Pick 2 spaces, 4 spaces or a tab, and choose where braces go.
Runs in your browser. Nothing is uploaded.
JavaScript
Formatted JavaScript
How to use it
- Paste your JavaScript into the input box, or open a .js file (up to 5 MB) or drop it on the box.
- Pick the indent, the brace style and, if you want it, a line wrap width.
- Choose Format. The result appears in the output box.
- Copy the result or download it as a .js file.
What the formatter changes and what it leaves alone
The formatter uses the js-beautify library. It changes whitespace only: indentation, line breaks and the spaces around operators, commas and braces. It does not add or remove semicolons, switch quote styles, rename variables or reorder code. Blank lines you wrote between statements are kept, up to two in a row. That makes the output safe to diff against the original, because every token is still there in the same order.
It formats code, it does not check it
js-beautify is not a parser, so it will not tell you about a missing bracket, an unclosed string or a reserved word used as a name. Broken input gives output that is only as broken as what you pasted. To find syntax errors, run the code through your editor, a linter or the browser console. JSX and TypeScript are not handled as separate languages, so look over the result for those files before you commit it.
Reading minified code
Formatting a minified bundle makes its structure readable, but it cannot bring back what the minifier threw away. Short names such as a, b and e stay as they are, and comments that were removed are gone. For debugging, a source map is the better route. The formatter is still handy for a quick look at a snippet from a vendor script or a build output.
Questions people ask
How do I format minified JavaScript?
Paste the minified code, pick an indent and choose Format. Each statement lands on its own line with nested blocks indented. Names that the minifier shortened stay short, because that information is not in the file, but the layout becomes easy to follow.
Does the formatter change what my code does?
It only changes whitespace, so the code should behave the same. It does not add or remove semicolons or change quotes. One exception to keep in mind: code that relies on automatic semicolon insertion should still be reviewed, since line breaks matter there.
Can it format JSX or TypeScript?
It is built for plain JavaScript. JSX and TypeScript may come out fine on simple files, but they are not supported as such, so check the output. A dedicated formatter for your project, run in the editor, is the safer choice for those.
Why did it not report a syntax error?
Formatting and syntax checking are different jobs. The beautifier lays out the tokens it sees without building a syntax tree, so a missing brace does not stop it. Use a linter or run the code to find syntax errors.
What is the difference between 2 spaces, 4 spaces and tabs?
The choice is only style. Two spaces is common in front-end projects, four spaces in many back-end ones, and tabs let each reader set their own width. Follow your project's style guide or editor config so diffs stay small.
Is there a file size limit?
Opening a file is limited to 5 MB. Pasted text has no fixed limit, but very large files make the page slow because the work happens in your browser tab.
About this tool
Uses the js-beautify library, which re-indents code and puts statements and braces on their own lines. It is a formatter, not a parser: it does not check syntax, so a missing bracket or an unclosed string is not reported and the output is only as correct as the input. It does not add or remove semicolons, change quotes, rename anything or reorder code. Line breaks you left between statements are kept, up to 2 in a row. JSX and TypeScript are not supported as such, so check the result on those files. Minified code that contains comments can only be restored to readable layout; the original variable names are not recovered.