About the JavaScript Beautifier
Compressed JavaScript is hard to read on one line. This beautifier lays it out the way a code editor would: one statement per line, every block indented by how deeply it is nested, and spaces around operators and after commas. That makes a one-line tracking snippet, a minified function or code copied from a web page easy to follow.
Paste the script and the formatted code fills the Result box, refreshed with every keystroke. Names, strings and logic are left as they were; only whitespace and line breaks change.
What the beautifier does to your code
The script is read token by token with the open-source js-beautify formatter, which runs inside the page. Because it recognises strings, template literals, regular expressions and comments, a semicolon or brace inside "a;b{c}" or /a;b{2}/ is left alone, and only real statements and blocks are laid out.
Each block opened by { is indented two spaces deeper than the line that opened it, and its closing } lines up with that line again. The for (let i = 0; i < 3; i++) header stays on one line, else and catch stay on the line of the closing brace, and spaces are added around = + < => and after commas.
Before any of that, your paste is scanned for signs of JavaScript, such as keywords like function, const or return, an arrow =>, a console call or a function call followed by a brace or semicolon. Text with none of these produces a warning instead of output.
Assumptions and limits
- There is no syntax check. Code with a missing bracket or quote is still laid out, but the indentation goes wrong from that point, and nothing tells you why.
- Missing semicolons are not added. Statements that relied on line breaks keep them, and code that was already formatted keeps at most one blank line between statements.
- Long lines are not wrapped, so a long chain such as fetch(url).then(...).then(...) stays on one line until it opens a block.
- It is a JavaScript formatter. TypeScript type annotations and JSX are not understood and can come out with odd spacing, such as age ? : number.
- Minified variable names stay short: the beautifier changes layout, not names.
Worked examples
Beautify a minified JavaScript one-liner
A 70-character line holding a function and two statements becomes five lines. The return statement is indented inside the function, the closing brace lines up with function, and each of the following statements gets its own line.
Input:
function add(a,b){return a+b;}const total=add(2,3);console.log(total);
Output:
function add(a, b) {
return a + b;
}
const total = add(2, 3);
console.log(total);An if/else block
Each branch opens onto its own indented line, so you can see at a glance which call runs in which case.
Input:
if(x){y();}else{z();}
Output:
if (x) {
y();
} else {
z();
}Strings that contain semicolons and braces
The string and the regular expression are copied exactly, while the for loop around them is opened up normally.
Input:
var s="a;b{c}";for(let i=0;i<3;i++){f(i)}
Output:
var s = "a;b{c}";
for (let i = 0; i < 3; i++) {
f(i)
}How to use the JavaScript Beautifier
- Paste the JavaScript. Replace the sample function in the Input Text box with the script you want to read.
- Read the formatted code. The Result box shows one statement per line with nested blocks indented, updating as you type.
- Copy what you need. Press Copy to take the formatted code into your notes, a code review or your editor.
Frequently asked questions
How do I make minified JavaScript readable?
Paste it into the input box. Every statement moves to its own line and each block is indented by how deeply it is nested. What was a wall of code becomes something you can scan for a function name, a URL or an event.
Is the beautified code safe to run?
Yes, for valid JavaScript. Only whitespace between tokens changes; strings, template literals and regular expressions are kept intact, and no semicolons are added or removed, so the code does the same thing. Keep the original anyway if you only need a reading copy.
Does the JavaScript beautifier rename or deobfuscate variables?
No. Short names like a, b and r stay exactly as they are, and no logic is rewritten. The tool only changes layout; it can make obfuscated code easier to scan but can't restore the original names.
Can I format JSON or TypeScript with it?
JSON, yes: objects open onto indented lines, though short arrays stay on one line. TypeScript only partly: plain code formats well, but type annotations and interfaces can get odd spacing, so a TypeScript-aware formatter such as Prettier in your editor is the better choice there.
What if my code has a syntax error?
It is formatted anyway, because the beautifier lays out tokens rather than checking the program. A missing closing brace usually shows up as code indented one step too far from that point to the end, which can help you find it.
Is my script sent anywhere?
No. The formatter is loaded with the page and runs in your browser, and the code you paste isn't uploaded or saved, so private or client scripts stay on your machine.
This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.