Core Configuration Options
You'll learn how to customize Prettier's five essential formatting rules using .prettierrc.
What These Options Do
Prettier applies opinionated defaults, but the five core options let you tailor formatting to your team's preferences without getting lost in endless configuration debates.
Setting Up .prettierrc
Create a .prettierrc file (JSON format) in your project root. This file controls how Prettier reformats your code:
{
"printWidth": 80,
"tabWidth": 2,
"semi": true,
"singleQuote": false,
"trailingComma": "es5"
}
The Five Core Options
printWidth – Maximum line length before Prettier wraps code (default: 80). Think of it as the "column width" of a newspaper—keeps lines readable.
tabWidth – Number of spaces per indentation level (default: 2). Controls how far code is indented when nested.
semi – Whether to add semicolons at statement ends (default: true). Set to false if your team prefers the semicolon-free style.
singleQuote – Use single quotes instead of double quotes for strings (default: false). Popular in many JavaScript projects for cleaner-looking code.
trailingComma – Add trailing commas where valid (default: "es5"). Options are "none", "es5" (objects/arrays), or "all" (including function parameters). The ES5 setting prevents unnecessary diffs when adding array/object items.
Example Configurations
Minimal setup (uses all defaults):
{}
Team-friendly setup:
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all"
}
Key Takeaway: Configure Prettier's five core options—printWidth, tabWidth, semi, singleQuote, and trailingComma—in .prettierrc to match your team's style while maintaining automatic, consistent formatting across your codebase.