JS Formatter
Format and indent JavaScript so it is easy to read.
Runs in your browser Your input never leaves your device.
About this tool
Paste JavaScript and the tool re-indents it and puts statements and blocks on separate lines using the js-beautify library, with a 2 or 4 space indent. It reformats whitespace only. It does not rename variables, add or remove semicolons, check your syntax or run your code, so a script with an error is still formatted as far as the tool can read it. Minified code becomes readable, but original variable names lost during minification do not come back. Everything runs in your browser and nothing you paste is uploaded.
How to use it
- Paste your JavaScript into the input box.
- Pick a 2 or 4 space indent.
- Read the formatted code in the output.
- Press Copy to use it.
Example
Existing semicolons are kept and missing ones are not added.
function add(a,b){return a+b}const x=add(1,2);function add(a, b) {
return a + b
}
const x = add(1, 2);Common problems
- Minified variable names are still a, b, c
- Formatting cannot recover names that were removed when the code was minified.
- Output looks broken after a syntax error
- The formatter does not validate. Check for missing brackets or quotes in the source.
- JSON or TypeScript input
- Plain JavaScript is expected. JSON usually works; use the JSON Beautifier for it.