Formatters
Beautify JavaScript code with 4-space indentation
JavaScript Formatter re-indents the code you paste four spaces per nesting level and normalizes spacing around operators, so a minified one-liner comes back as statements you can actually read. Developers use it to inspect snippets recovered from build maps, restore structure to collapsed files, and align code before review. Strings, comments, and identifiers keep their exact content; only whitespace moves. Template literals, optional chaining, and arrow functions pass through in place.
How to use JS Formatter
- Open JS Formatter in the Toolbox101 app.
- Paste the JavaScript into the
JavaScriptbox; a minified bundle fragment or a badly indented file works. - Pick
Indent: 2 spaces, 4 spaces (the default) or Tab. - Read the re-indented code in the
Outputbox, with spaces added around operators. Strings and comments keep their exact text, and modern syntax such as template literals is left in place. - Click
Copyto put the formatted code on your clipboard.
Worked example
JS Formatter returns the output below for this input.
Input
const users=[{id:1,name:"Ada"},{id:2,name:"Alan"}];function findUser(id){return users.find(u=>u.id===id)||null;}Output
const users = [{
id: 1,
name: "Ada"
}, {
id: 2,
name: "Alan"
}];
function findUser(id) {
return users.find(u => u.id === id) || null;
}Check it yourself: open JS Formatter and enter the same input.
Frequently asked questions
Will formatting change what my code does?
No. The pass is purely lexical: indentation and line breaks move, and spaces appear around operators such as === and =>, but tokens keep their order and values, so the program behaves identically. Nothing is ever transpiled, renamed, or executed.
Does it minify JavaScript as well?
No, the direction is one-way: this tool adds indentation and line breaks for reading. To produce minified output, run your own build pipeline with a tool such as esbuild or terser after editing, rather than pasting code back and forth.
Does it format TypeScript or JSX?
js-beautify tokenizes rather than fully parses, so typical TypeScript and JSX can come out with odd indentation in places, and syntax errors are not reported. The page targets plain JavaScript, which is what its defaults are tuned for; use a dedicated tool for TypeScript.
Use JS Formatter now
Runs in your browser. Nothing you type is uploaded.