JavaScript Formatter
Format JavaScript code.
About this tool
Paste JavaScript and format it with Prettier, the same formatter most projects use. Every Prettier option that applies to JavaScript is available: tab width, tabs, print width, semicolons, quotes, quote props, trailing commas, bracket spacing, arrow parentheses, object wrapping, JSX options, line endings and the experimental ternary and operator-position styles. If your code has a syntax error you get the line and column instead of silently broken output. JSX is understood, and nothing leaves your browser.
How to use
How it works
The code is parsed into a syntax tree with Prettier's Babel parser by default (or babel-flow, acorn, espree, meriyah or flow if you pick one) and printed again from scratch using your options, so layout is decided by the code's structure, not by how you spaced it. Long calls and objects wrap at the print width, quotes are normalised to your choice and semicolons are added or omitted consistently. Only the parser you choose is downloaded, and the CSS, GraphQL, HTML and Markdown plugins load only if your code contains matching template literals. Your option choices are remembered in this browser. If Prettier cannot load, a basic indentation formatter is used and the page says so.
Worked example
Messy to tidy
- Input
- const a={b:1,c:'x'};function f(x){if(x){return x+1}else{return 0}}
- Output
- const a = { b: 1, c: "x" }; function f(x) { if (x) { return x + 1; } else { return 0; } }
- Walkthrough
- Spaces are added around operators and braces, the single-quoted string becomes double-quoted, and each block gets its own indented lines.
Limitations
- Code with a syntax error is not formatted; fix the reported line and try again.
- Prettier has opinions: it will not keep hand-aligned columns or extra blank lines beyond one.
- Only options that apply to JavaScript are shown; file-level settings such as overrides, plugins and.prettierignore are not.
- Some parsers are stricter than others: acorn, espree and meriyah do not accept Flow annotations, and flow does not accept every Babel proposal.
- Very large files may take a moment, since formatting runs in your browser.
Questions
Is this the real Prettier?
How do I switch to tabs or single quotes?
Which options can I change?
Can I reuse my settings in a project?
Which parsers can I choose?
Are my settings saved?
What happens with a syntax error?
Does it handle JSX and modern syntax?
Is my code uploaded?
Features
- Real Prettier engine
- Every JavaScript Prettier option
- Parser choice: babel, babel-flow, acorn, espree, meriyah, flow
- Copy as.prettierrc with only non-default options
- Reset to Prettier defaults
- Settings remembered in your browser
- Bytes before and after
- Line and column for errors
- Runs in your browser
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
SQL Tutorial - Full Database Course
freeCodeCamp.org
SQL formatters shine when reviewing long beginner queries.
Watch on YouTubeLearn Regular Expressions - Crash Course
freeCodeCamp.org
Regex primer for tester and explainer pages.
Watch on YouTube
- Prettier documentation
Prettier
Industry-standard formatting rules—compare with quick browser formatters.
- web.dev
Google
Modern web guidance that pairs with encoding and tooling pages.