Format JavaScript
Rewrites your code with clean indentation, line breaks, and spacing using Prettier. Long, minified, or messy code becomes easy to read and review.
function f(a){return a*2}Afterfunction f(a) {
return a * 2;
}Paste minified or messy JavaScript and get it back with clean indentation, line breaks, and spacing. Choose your quote style and indentation, or minify instead. Everything runs in your browser, so your code stays on your device.
Format supports JavaScript and JSX. Minify supports plain JavaScript. Style options apply to Format.
JavaScript often ends up minified or crammed onto a few lines, which is hard to read and easy to make mistakes in. A formatter rewrites the code with clean indentation, one statement per line, and consistent spacing, so the structure is clear at a glance. It does not change what the code does, only how it is laid out. This tool formats your code with Prettier and can also minify it when you want a smaller copy.
Rewrites your code with clean indentation, line breaks, and spacing using Prettier. Long, minified, or messy code becomes easy to read and review.
function f(a){return a*2}Afterfunction f(a) {
return a * 2;
}Removes comments and extra whitespace with Terser to make a compact copy of plain JavaScript. Variable and function names stay the same. JSX is not supported by Minify.
// double it
const double = x => x * 2;Afterconst double=x=>x*2;Adds semicolons at the end of statements. Turn it off to omit optional semicolons. Prettier still adds them where needed to keep the code working.
const x = 1Afterconst x = 1;Prefer single or double quotes for strings and choose 2 or 4 spaces per level. Prettier may use the other quote style to avoid extra escapes. These settings apply to Format.
let s = "hi"Afterlet s = 'hi';A formatter helps any time code is hard to read. These are the cases that come up most:
This tool formats with Prettier, the most widely used JavaScript formatter. To get the same result across a whole project:
| To | Use |
|---|---|
| Format every file | npx prettier --write . |
| Check without changing files | npx prettier --check . |
| Match the settings used here | Add "tabWidth", "semi", and "singleQuote" with your choices to a .prettierrc file |
| Format when you save | Install the Prettier extension in VS Code and turn on Format On Save |
Anything you do not set here uses Prettier's defaults: lines wrap at 80 characters, and trailing commas are added wherever JavaScript allows them.
For JSON data, use theJSON formatter and validator. For markup, use the HTML formatter and beautifier.