JavaScript Formatter
Beautify JavaScript code.
About the JavaScript Formatter
Reformats minified or badly indented JavaScript into something readable, at 2 or 4 spaces. It is deliberately conservative: statements get their own lines and the indentation is rebuilt, but your blank lines survive and long lines are not rewrapped. Use it to read a bundled file, review a snippet pasted into a bug report, or tidy code that never went through a formatter.
How to use the JavaScript Formatter
- Paste your JavaScript into the input panel, or press Sample to load an example.
- Choose 2 spaces or 4 spaces from the Indent selector.
- Press Beautify to reformat the code.
- Copy the result, or Download it as script.js.
Frequently asked questions
- Does it check my syntax?
- No. This is a reformatter, so it re-indents what it can and passes broken code through unchanged instead of reporting an error. Run the file through the JavaScript Minifier if you want a real parse.
- Is this the same as Prettier?
- No. It uses js-beautify, which re-indents your code without reprinting it to a target line width. Prettier rebuilds the output from the syntax tree and will move things its own way; js-beautify leaves your line structure largely intact.
- Can it unminify code?
- It restores indentation and line breaks, which is usually enough to read minified code. It cannot bring back the original variable names or the comments, because the minifier threw them away.
- Does it keep my blank lines?
- Yes, up to two consecutive blank lines. Longer runs are collapsed to two.
- Is my code uploaded?
- No. Formatting happens in your browser; this page has no server side.
Related tools
- JavaScript MinifierMinify JavaScript with Terser.
- JSON FormatterBeautify, minify, and validate JSON instantly.
- HTML FormatterBeautify and format HTML markup.
- CSS Beautify & MinifyFormat or minify CSS stylesheets.
- SQL FormatterFormat SQL queries for readability.
- XML FormatterFormat and beautify XML documents.