Prettier explained: why format your code?
Try it now: Code Formatter, free and private in your browser.
Open Code FormatterPrettier is a code formatter. It reads your code and prints it again in one consistent style: same indentation, same quotes, same line breaks. You stop arguing about style and just write.
Why format code automatically?
- Consistency: every file looks the same, no matter who wrote it.
- Cleaner reviews: diffs show real changes, not spacing fights.
- Less thinking: you stop deciding where lines should break.
- Fewer syntax slips: if Prettier cannot parse your code, you find the error early.
What Prettier formats
JavaScript, JSX, TypeScript, JSON, HTML, CSS, SCSS, Less, Markdown, YAML and GraphQL work out of the box. Languages such as Python, Java and PHP need community plugins, and other formatters usually do those jobs better.
Prettier is not a linter
A linter such as ESLint finds likely bugs, like unused variables. Prettier only changes layout. Most projects use both.
The few options it has
printWidth: how long a line can be before wrapping (default 80).tabWidthanduseTabs: indentation.semi: add semicolons or not.singleQuote: use single quotes.trailingComma: commas after the last item.
Prettier is deliberately opinionated, so there are few settings. That is the point.
Set it up in a project
npm install --save-dev prettier
npx prettier --write .
Add a .prettierrc file if you want to change defaults:
{
"semi": false,
"singleQuote": true,
"printWidth": 100
}
Then turn on "format on save" in your editor, and optionally run Prettier before each commit.
Format a snippet without installing anything
For a quick job, paste the code into the online formatter, choose your options and copy the result. It uses the same Prettier engine.
FAQ
- Is Prettier free?
- Yes. It is open source.
- Will Prettier change how my code works?
- No. It only changes layout, not behavior.
- What is the difference between Prettier and ESLint?
- Prettier formats. ESLint finds problems. Use both.
- Can I make Prettier ignore a file?
- Yes. List paths in a
.prettierignorefile.