JavaScript & TypeScript Beautifier — Clean Indentation for Dense Code
Re-format dense JavaScript code blocks with balanced braces and indentation.
- The code is read token by token: regexes are told apart from division, template literals with nested ${…} and quoted strings are left alone, and line breaks that decide automatic semicolons (return, ++, --) are kept.
- The beautifier also reads TypeScript (types, generics, optional properties, as const). The output is tested with esbuild: the original program and the formatted one are exactly the same.
When to use the JavaScript / TypeScript Code Beautifier
Reading minified code
Built scripts or snippets copied from the console are usually one long line. The beautifier writes one statement per line, indents every block and keeps } else, } catch and }); together so the flow is easy to follow while debugging.
The program does not change
The code is read token by token: regexes are told apart from division, template literals with nested ${…} are left alone, and line breaks that decide automatic semicolons, such as after return, are kept. The output is tested with esbuild on pdf-lib, preact and this site's own scripts.
TypeScript works too
Type annotations, generics such as Record<string, number>, optional properties name?: string and as const are read correctly. Hundreds of this site's TypeScript files are formatted and compared with the originals by esbuild, with the same result.
Indentation to match your team
Choose two spaces, four spaces or a tab to match the project's style rules. Line and block comments stay where they were, and multi-line text inside template literals is left untouched.
Frequently asked questions
Are variable names changed?
No. The beautifier only arranges spaces, line breaks and indentation.
Is JSX supported?
Not fully. JSX is read as plain text so its indentation may be untidy; the logic and strings around it stay safe.
What about broken code?
The code is still formatted as far as possible without guessing missing parts. Check your browser's or editor's error message to find the cause.
Is my code uploaded?
No. Everything runs in your browser.
Similar tools
- JavaScript Code Minifier & Whitespace StripperRemove comments and redundant whitespace from JS snippets locally.
- HTML Beautifier & Indentation PrettifierRe-indent messy single-line HTML markup into readable nested element trees.
- HTML Whitespace & Comment MinifierCompress HTML documents by removing redundant whitespace & HTML comments.
- HTML to Clean GitHub Markdown ConverterConvert headings, links, bold/code tags & lists from HTML into clean Markdown.