How to format JavaScript
Paste the code
Paste your JavaScript or open a .js file, or try “Example”.
Choose the indent
2 spaces, 4 spaces or Tab, and the line width.
Copy or download
Press “Format”, then copy or download the result.
Options
| Option | Values | Most common |
|---|---|---|
| Indent | 2 spaces, 4 spaces, Tab | 2 spaces in most web projects |
| Line width | 80, 100 or 120 characters | 80; longer lines are wrapped |
Tips
Find syntax errors. If the code can’t be formatted there’s a syntax error: you get the line, column and reason.
Read a library’s code. .min.js files become readable once formatted, even though variable names stay short.
Your code works the same. Formatting only changes whitespace, line breaks and quotes.
FAQ
How do I unminify JavaScript?
Paste the minified code and press “Format”. Line breaks and indentation come back; shortened names like a and t can’t be turned back into the original names.
Does formatting change how the code works?
No. We tested 13 well-known libraries and test programs: we compared the code tree (AST) before and after formatting and ran the programs to compare their output, and they matched.
Does it support TypeScript?
No, it’s for JavaScript and JSX. TypeScript code will show an error at the first type annotation.
Which engine does it use?
Prettier 3.9 (MIT) with the Babel parser, running in your browser.
