JavaScript Formatter
Format and beautify JavaScript and JSX online with Prettier. Choose indentation, quotes, semicolons and line width; your code is formatted in your browser.
Runs in your browser · Nothing uploaded · No sign-up
Something not working, or missing a feature? Send feedback
About the JavaScript Formatter
The JavaScript Formatter applies Prettier, the formatter most JavaScript projects use, so code looks the same no matter who wrote it. It handles modern syntax and JSX.
Everything runs in your browser, so your input is never uploaded to a server.
How to use the JavaScript Formatter
- Paste JavaScript or JSX, or open a file.
- Set indentation, single or double quotes, semicolons and line width.
- Copy or download the formatted code.
Example
Input
const total=items.filter(i=>i.active).map(i=>i.price*i.qty).reduce((a,b)=>a+b,0);if(total>100){applyDiscount(total,"SAVE10")}Result
const total = items
.filter((i) => i.active)
.map((i) => i.price * i.qty)
.reduce((a, b) => a + b, 0);
if (total > 100) {
applyDiscount(total, 'SAVE10');
}
The chained calls are split one per line, arrow parameters get parentheses and the string switches to single quotes (the default setting).
Common mistakes
- Syntax errors. A formatter is not a linter: code with a missing bracket is reported with its line and column, not fixed. Correct that position and format again.
- TypeScript syntax. Type annotations such as (id: number) are a syntax error for the JavaScript parser. Use the TypeScript Formatter for .ts and .tsx code.
- Different settings than your project. Match quotes, semicolons and line width to your .prettierrc, or the formatted code will produce a noisy diff when you commit it.
Works well with the JavaScript Formatter
- TypeScript Formatter: format TypeScript and TSX with the same engine.
- JavaScript Minifier: compress the code again for production.
- JavaScript Compiler: run the snippet and see its console output.
Frequently asked questions
Is the output the same as running Prettier locally?
Yes, it uses Prettier itself with the options you choose, so the result matches a project configured the same way.
Can it fix syntax errors?
No. Code must parse before it can be formatted; the error message shows where parsing failed.
Does it support JSX?
Yes. React JSX is formatted too, with long elements wrapped in parentheses across several lines.
Is my code sent to a server?
No. Prettier runs in your browser, so the code stays on your device.
Guides and tutorials
Related tools
JSON Formatter
Format and beautify JSON with configurable indentation and optional key sorting. Errors are reported with exact line and column.
HTML Formatter
Format and beautify messy or minified HTML into clean, indented markup with Prettier, including embedded CSS and JavaScript. Runs locally in your browser.
CSS Formatter
Format and beautify CSS, SCSS and Less online with Prettier. Turn minified or messy stylesheets into readable, consistently indented code in your browser.
TypeScript Formatter
Format and beautify TypeScript and TSX online with Prettier, including types, generics and decorators. Choose indentation, quotes and semicolons.
PHP Formatter
Format PHP code online with Prettier for PHP (@prettier/plugin-php): PSR-12 braces, spacing and 4-space indentation. No install, and nothing is uploaded.
SQL Formatter
Format and beautify SQL queries online for MySQL, PostgreSQL, SQLite, SQL Server and more, with keyword casing and indentation options. Runs in your browser.