JavaScript formatter
Reformat JavaScript or TypeScript into consistent, readable code.
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.