About JavaScript Formatter
Paste code that is cramped, inconsistent or squeezed onto one line and get it back in Prettier’s widely used layout: one statement per line, consistent spacing, long calls and objects broken across lines, and JSX nested by level. Choose TypeScript to keep type annotations, interfaces, generics and TSX.
Set the style your project uses: two or four spaces or tabs, single or double quotes, with or without semicolons, trailing commas and a line width of 80, 100 or 120. Code that cannot be parsed is not guessed at; you get the line and column of the problem instead.
How it works
- Your code is parsed with Prettier’s Babel parser for JavaScript and JSX, or its TypeScript parser for TypeScript and TSX, then printed again in Prettier’s standard layout with the options you set.
- Comments, string contents and the meaning of the code are kept. What changes is whitespace, line breaks, quotes, semicolons, trailing commas and parentheses that do not change meaning.
- Formatting runs in a background worker, so a large file never freezes the page, and Prettier is loaded only when you first format something.
Questions
What happens if my code has a syntax error?
Nothing is changed. The tool shows the line and column where the parser stopped and what it expected, so you can fix it at the source. Check that the language is set right: type annotations are a syntax error in JavaScript mode.
Will this make minified code readable?
It restores the layout: lines, indentation and spacing. It cannot bring back names a minifier shortened to single letters, or comments it removed.
Does my code leave my device?
No. Prettier is loaded into this page and runs in your browser. Your code is never uploaded.
How large a file can it format?
Up to 2 MB of text. Larger input is refused with a message before anything is processed.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.