JavaScript Formatter
Beautify JavaScript with consistent indentation and spacing. It works on tokens rather than a full syntax tree, so it is fast and tolerant but not as thorough as a full code formatter.
Use the tool
Why this tool exists
Minified scripts from a CDN, a bookmarklet or a bug report are unreadable, and reading them is often the quickest way to find out what a library actually does. Re-indenting turns a single line into code you can follow.
This formatter puts statements on separate lines, indents blocks, and spaces operators and keywords sensibly, while leaving strings, regular expressions and template literals untouched. It reads tokens rather than building a syntax tree, which means it copes with fragments and slightly broken code, but its decisions are simpler than those of a tool like Prettier. It does not undo renaming done by a minifier, so variable names stay short. Nothing is uploaded; the formatting happens in your browser.
How to use it
- Paste your JavaScript into the input box.
- Choose the indent: 2, 4 or 8 spaces, or a tab.
- Read the beautified code in the output.
- Copy it into your editor.
Frequently asked questions
Is it as good as Prettier?
No. It uses tokens, not a full parse, so it applies simpler rules and will not match the style or line wrapping of a dedicated formatter. It is meant for making code readable quickly.
Does it change what the code does?
It should not. Only whitespace and line breaks change. Strings, regular expressions and template literals are kept intact. Test any code you plan to run.
Can it restore original variable names?
No. If a minifier shortened names to a, b and c, the formatter cannot recover them. It only restores layout.
Does it support modern syntax?
Common modern syntax such as arrow functions, async and await, template literals and optional chaining is handled. Very new or unusual syntax may be spaced imperfectly.