JavaScript Beautifier
Format javascript content for easier reading.
About JavaScript Beautifier
Single-line JavaScript from a minified widget, a bookmarklet or a console paste is hard to follow. Adding line breaks at statements and blocks gives you a rough view of the structure, which helps when you want to see roughly what a small snippet does. It is not meant for reformatting a real codebase.
How it works
This is a simple regex formatter, not a parser. It runs three replacements in order. A line break goes after every semicolon. Every opening brace becomes a space, the brace, a line break and two spaces. Every closing brace is put on its own line, with a line break before and after. Only the first statement after an opening brace gets indented, and nesting depth is never tracked. Semicolons and braces inside strings, regex literals and for loop headers are split too. The output can be saved as pretty.js.
How to use JavaScript Beautifier
- Enter the text or data in the format shown in the text box above (Paste JavaScript).
- Select “Run tool” and check the result before copying or downloading it.
Worked example
Input: function add(a,b){return a+b;}. Output: function add(a,b) { on the first line, then return a+b; indented two spaces, then an empty line, then the closing brace. The empty line appears because both the semicolon rule and the closing-brace rule add a line break.
Tips for a better result
- Use it to get a first look at short minified snippets. For code you will edit or commit, use Prettier or your editor's formatter.
- Be careful copying output back if the code has for(;;) loops or strings with semicolons. Those get split onto new lines and may need fixing.
- After formatting, use your editor's reindent command to fix nested blocks, since only one level of indentation is added.
Frequently asked questions
Why are nested blocks not indented properly?
The tool does not count nesting. It only indents the line right after each opening brace by two spaces. Inner blocks and later statements stay at the margin, so deep code needs a real formatter.
Can it break my code?
Usually it only adds line breaks, which JavaScript tolerates. But splitting inside strings or template literals changes their contents, and a line break after return can change behavior. Review the output before running it.
Does it rename or unminify variables?
No. Short names like a or t stay short. Minified code loses its original names, and no formatter can recover them. Only source maps from the original build can.
What to check
A formatted or parsed result is not proof that code is secure, correct or production-ready. Never paste production secrets.
Read the Privacy Policy for information about local processing, connected services and advertising.