JavaScript Formatter
Paste minified or badly indented JavaScript to get clean, consistently formatted code. Choose spaces or tabs, collapse or Allman-style braces and an optional wrap length; modern syntax such as arrow functions, template literals and async/await is supported. A quick check warns when brackets look unbalanced.
How to use the JavaScript Formatter
- Paste your code or press Load example.
- Set indentation, brace style and wrap length.
- Press Format JavaScript.
- Copy the formatted code or download it as a .js file.
Features
- Indentation with 2 or 4 spaces or tabs
- Collapse, expand (Allman), end-expand and preserve-inline braces
- Understands ES2015+ syntax and JSON
- Optional line wrapping and blank-line preservation
- Warnings for unbalanced braces, brackets and parentheses
Benefits
- Read minified bundles and snippets when debugging
- Tidy code before sharing it in a review or a question
- Your code never leaves your computer
Frequently asked questions
Can it restore the original variable names?
No. Formatting only adds whitespace and line breaks. Names that were shortened by a minifier stay shortened.
Does it work with TypeScript?
Most TypeScript formats acceptably because it shares JavaScript syntax, but type-specific constructs such as generics may not always indent ideally.
Does it check that my code runs?
It is a formatter, not a compiler. It warns about unbalanced brackets but does not execute or fully parse the code.
Related tools
- JSON Formatter — Beautify or minify JSON with 2-space, 4-space or tab indents, sort keys and browse it as a collapsible tree.
- JSON Validator — Check JSON syntax as you type, see the exact line and column of any error and get warnings for duplicate keys.
- XML Formatter — Pretty-print or minify XML with comments, CDATA and DOCTYPE support, plus a well-formedness check with error positions.
- HTML Formatter — Beautify HTML with your choice of indentation and line wrapping, including inline <script> and <style> blocks.
- CSS Formatter — Beautify minified CSS into readable rules with custom indentation, brace style and one selector per line.
- Code Minifier — Minify JavaScript with Terser, plus CSS and HTML, and see the original size, minified size and percentage saved.