Skip to content

JavaScript formatter

Reformat JavaScript or TypeScript into consistent, readable code.

Input
80
Output

JavaScript formatter

Paste JavaScript or TypeScript and this tool reformats it into consistent indentation, spacing and line breaks. It reindents minified or inconsistently formatted code, normalizes blocks and object literals, and keeps expressions such as ternaries, generics, template literals, optional chaining and arrow functions spaced the way a human would write them by hand.

Options control the details rather than the structure. Choose 2 spaces, 4 spaces or tabs for indentation, and single or double quotes — string content is re-escaped correctly either way, so a quote character inside the string is never mangled. Semicolons can be added at the end of every statement or stripped in favor of automatic semicolon insertion; multi-line objects and arrays can end with a trailing comma or not. Max line width controls when a long object literal or argument list wraps onto multiple lines instead of running off the edge of the screen. Minify collapses the same code onto a single line with the whitespace and comments removed, for when you need a compact copy rather than a readable one.

This is a formatter, not a linter or a bundler: it does not rewrite logic, rename variables or resolve imports, and it does not run your code. It aims to keep the output valid for realistic JavaScript and TypeScript, including classes, async functions, destructuring, spread syntax and decorators — genuinely malformed input (an unterminated string or comment) is reformatted on a best-effort basis rather than rejected outright.

Everything runs locally in your browser. Your source code is never uploaded to a server, which matters for proprietary or unpublished code as much as for a quick snippet from a bug report. Copy the formatted result, download it as a .txt file, or send it into another tool to keep working.

FAQ

Does it support TypeScript, not just JavaScript?
Yes. Type annotations, generics, interfaces, optional properties and other common TypeScript syntax are recognized and formatted, alongside plain JavaScript.
What does "Minify" do differently from the other options?
It removes comments and unnecessary whitespace and puts the code on one line, while still keeping the semicolons needed to separate statements safely. It is a compact formatting mode, not a full minifier — it does not rename variables or apply other size optimizations.
Will it break my code?
The formatter only changes whitespace, quote characters and semicolons — it never rewrites expressions or logic. Comments and string contents are preserved exactly as written.
What happens with a long line, like a big object literal?
Set "Max line width" and an object or array literal that would exceed it is split across multiple lines, one entry per line, instead of running past the edge of the page.
Is my code uploaded anywhere?
No. Formatting runs entirely in your browser — your source code never leaves your device.