JavaScript Formatter
Make minified or inconsistent JavaScript readable again. The formatter re-indents blocks, puts statements on separate lines and applies the brace style you choose. It only changes whitespace: your code is treated as text and is never run, evaluated or sent anywhere.
Format Your JavaScript
Formatted JavaScript
Result
How to Use the JavaScript Formatter
- Paste your JavaScript into the box.
- Choose indentation, brace style and optional line wrapping.
- Press Format.
- Copy the result or download it as formatted.js.
About This Tool
Developers reading minified bundles or code snippets from a browser console, reviewers who want consistent layout, and students tidying homework.
Input: JavaScript ยท Output: Formatted JavaScript (.js).
Features and Limitations
Features
- Indentation with 2 spaces, 4 spaces or tabs; collapse, expand or end-expand brace styles.
- Understands modern syntax such as arrow functions, template literals, classes, async and await.
- Optional wrapping at 80, 100 or 120 characters.
- Uses the open-source js-beautify library bundled with this site. Nothing is executed.
Limitations
- Beautifying does not restore original variable names: minified code stays cryptic, just readable.
- The tool does not check syntax, so broken code is reformatted on a best-effort basis. Run a linter or your browser console to find errors.
- Unusual constructs such as regular expressions after certain keywords or mixed JSX/TypeScript may be spaced oddly.
- It does not add or remove semicolons.
- Results are computed in your browser; nothing you enter is sent to a server.
Example
function f(a,b){if(a){return b}} becomes a function block with the if statement indented on its own lines.
Frequently Asked Questions
Does the tool run my JavaScript?
No. The code is processed as plain text by a formatter. It is never evaluated, so pasting untrusted code is safe.
Will formatting change what my code does?
It should not. Only whitespace and line breaks change, and no semicolons are added or removed. Automatic semicolon insertion rules can make line breaks matter in rare cases, so test important code after formatting.
Can it format TypeScript or JSX?
It is built for JavaScript. Simple TypeScript and JSX often come out fine, but the result is not guaranteed.
Can it unminify a bundle with short variable names?
It makes the layout readable but cannot recover the original names or comments.
Is my code uploaded?
No. Formatting happens in your browser.
Related Tools
More like this: all Format & Validate tools, all Developer & Web tools or the TinySandy home page.