2017-11-07 14:39:07 +11:00
---
id : configuration
title : Configuration File
---
2023-12-05 15:00:43 +08:00
You can configure Prettier via (in order of precedence):
2017-11-07 14:39:07 +11:00
2024-05-10 11:36:44 +01:00
- A `"prettier"` key in your `package.json` , or [`package.yaml` ](https://github.com/pnpm/pnpm/pull/1799 ) file.
2020-06-28 03:47:29 +02:00
- A `.prettierrc` file written in JSON or YAML.
2020-08-15 21:16:49 +08:00
- A `.prettierrc.json` , `.prettierrc.yml` , `.prettierrc.yaml` , or `.prettierrc.json5` file.
2024-12-21 10:39:45 +04:00
- A `.prettierrc.js` , `prettier.config.js` , `.prettierrc.ts` , or `prettier.config.ts` file that exports an object using `export default` or `module.exports` (depends on the [`type` ](https://nodejs.org/api/packages.html#type ) value in your `package.json` ).
- A `.prettierrc.mjs` , `prettier.config.mjs` , `.prettierrc.mts` , or `prettier.config.mts` file that exports an object using `export default` .
- A `.prettierrc.cjs` , `prettier.config.cjs` , `.prettierrc.cts` , or `prettier.config.cts` file that exports an object using `module.exports` .
2020-06-28 03:47:29 +02:00
- A `.prettierrc.toml` file.
2017-11-07 14:39:07 +11:00
2025-01-30 03:16:21 +01:00
:::info
TypeScript configuration files support requires [additional setup ](#typescript-configuration-files )
:::
2024-12-21 10:39:45 +04:00
2020-06-28 03:47:29 +02:00
The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn’ t) found.
2017-11-07 14:39:07 +11:00
2020-06-28 03:47:29 +02:00
Prettier intentionally doesn’ t support any kind of global configuration. This is to make sure that when a project is copied to another computer, Prettier’ s behavior stays the same. Otherwise, Prettier wouldn’ t be able to guarantee that everybody in a team gets the same consistent results.
2020-05-12 16:00:28 +03:00
2020-06-28 03:47:29 +02:00
The options you can use in the configuration file are the same as the [API options ](options.md ).
2017-11-07 14:39:07 +11:00
2024-12-21 10:39:45 +04:00
### TypeScript Configuration Files
2025-06-26 09:40:24 +08:00
TypeScript support requires Node.js>=22.6.0, and `--experimental-strip-types` is required before Node.js v24.3.0 to run Node.js.
2024-12-21 10:39:45 +04:00
```sh
node --experimental-strip-types node_modules/prettier/bin/prettier.cjs . --write
```
or
```sh
NODE_OPTIONS = "--experimental-strip-types" prettier . --write
```
2017-11-07 14:39:07 +11:00
## Basic Configuration
JSON:
2025-12-06 14:43:36 +08:00
```json title=".prettierrc.json or .prettierrc"
2017-11-07 14:39:07 +11:00
{
2018-09-29 09:40:19 +02:00
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true
2017-11-07 14:39:07 +11:00
}
` ``
2024-02-18 16:38:18 +01:00
JS (ES Modules):
2017-12-26 00:26:09 -07:00
2025-12-06 14:43:36 +08:00
` ``js title="prettier.config.mjs, .prettierrc.mjs, prettier.config.js, or .prettierrc.js"
2024-04-06 03:24:18 -07:00
/**
2025-02-15 12:18:09 +08:00
* @see https://prettier.io/docs/configuration
2024-04-06 03:24:18 -07:00
* @type {import("prettier").Config}
*/
2023-04-27 04:26:06 +02:00
const config = {
2022-08-01 10:51:31 +08:00
trailingComma: "es5",
tabWidth: 4,
semi: false,
singleQuote: true,
};
2023-04-27 04:26:06 +02:00
export default config;
2022-08-01 10:51:31 +08:00
` ``
2024-02-18 16:38:18 +01:00
JS (CommonJS):
2022-08-01 10:51:31 +08:00
2025-12-06 14:43:36 +08:00
` ``js title="prettier.config.cjs, .prettierrc.cjs, prettier.config.js, or .prettierrc.js"
2024-04-06 03:24:18 -07:00
/**
2025-02-15 12:18:09 +08:00
* @see https://prettier.io/docs/configuration
2024-04-06 03:24:18 -07:00
* @type {import("prettier").Config}
*/
2023-04-27 04:26:06 +02:00
const config = {
2018-09-29 09:40:19 +02:00
trailingComma: "es5",
tabWidth: 4,
semi: false,
singleQuote: true,
2017-12-26 00:26:09 -07:00
};
2023-04-27 04:26:06 +02:00
module.exports = config;
2017-12-26 00:26:09 -07:00
` ``
2024-12-21 10:39:45 +04:00
TypeScript (ES Modules):
2025-12-06 14:43:36 +08:00
` ``ts title="prettier.config.mts, .prettierrc.mts, prettier.config.ts, or .prettierrc.ts"
2024-12-21 10:39:45 +04:00
import { type Config } from "prettier";
const config: Config = {
trailingComma: "none",
};
export default config;
` ``
TypeScript (CommonJS):
2025-12-06 14:43:36 +08:00
` ``ts title="prettier.config.cts, .prettierrc.cts, prettier.config.ts, or .prettierrc.ts"
2024-12-21 10:39:45 +04:00
import { type Config } from "prettier";
const config: Config = {
trailingComma: "none",
};
module.exports = config;
` ``
2017-11-07 14:39:07 +11:00
YAML:
2025-12-06 14:43:36 +08:00
` ``yaml title=".prettierrc, .prettierrc.yml, or .prettierrc.yaml"
2018-09-29 09:40:19 +02:00
trailingComma: "es5"
tabWidth: 4
semi: false
singleQuote: true
2017-11-07 14:39:07 +11:00
` ``
2018-08-03 06:27:20 -04:00
TOML:
2025-12-06 14:43:36 +08:00
` ``toml title=".prettierrc.toml"
2018-09-29 09:40:19 +02:00
trailingComma = "es5"
tabWidth = 4
semi = false
singleQuote = true
2018-08-03 06:27:20 -04:00
` ``
2017-11-07 14:39:07 +11:00
## Configuration Overrides
2019-08-27 07:09:12 +02:00
Overrides let you have different configuration for certain file extensions, folders and specific files.
2017-11-07 14:39:07 +11:00
JSON:
2025-12-06 14:43:36 +08:00
` ``json title=".prettierrc"
2017-11-07 14:39:07 +11:00
{
"semi": false,
2017-11-22 19:27:40 +08:00
"overrides": [
{
2026-07-18 14:01:25 +08:00
"files": ["*.test.js"],
2017-11-22 19:27:40 +08:00
"options": {
"semi": true
}
2019-08-27 07:09:12 +02:00
},
{
"files": ["*.html", "legacy/**/*.js"],
"options": {
"tabWidth": 4
}
2017-11-07 14:39:07 +11:00
}
2017-11-22 19:27:40 +08:00
]
2017-11-07 14:39:07 +11:00
}
` ``
YAML:
2025-12-06 14:43:36 +08:00
` ``yaml title=".prettierrc"
2017-11-07 14:39:07 +11:00
semi: false
overrides:
2026-07-18 14:01:25 +08:00
- files:
- "*.test.js"
2018-07-29 15:44:21 +08:00
options:
semi: true
2019-08-27 07:09:12 +02:00
- files:
- "*.html"
- "legacy/**/*.js"
options:
tabWidth: 4
2017-11-07 14:39:07 +11:00
` ``
2017-11-22 19:27:40 +08:00
` files` is required for each override, and may be a string or array of strings. ` excludeFiles` may be optionally provided to exclude files for a given rule, and may also be a string or array of strings.
2017-11-07 14:39:07 +11:00
2018-09-29 09:40:19 +02:00
## Setting the [parser](options.md#parser) option
By default, Prettier automatically infers which parser to use based on the input file extension. Combined with ` overrides` you can teach Prettier how to parse files it does not recognize.
For example, to get Prettier to format its own ` .prettierrc` file, you can do:
2017-11-07 14:39:07 +11:00
2025-12-06 14:43:36 +08:00
` ``json title=".prettierrc"
2017-11-07 14:39:07 +11:00
{
2017-11-22 19:27:40 +08:00
"overrides": [
{
2026-07-18 14:01:25 +08:00
"files": [".prettierrc"],
"options": {
"parser": "json"
}
2017-11-22 19:27:40 +08:00
}
]
2017-11-07 14:39:07 +11:00
}
` ``
2018-12-27 08:05:19 -05:00
You can also switch to the ` flow` parser instead of the default ` babel` for .js files:
2018-09-29 09:40:19 +02:00
2025-12-06 14:43:36 +08:00
` ``json title=".prettierrc"
2018-09-29 09:40:19 +02:00
{
"overrides": [
{
2026-07-18 14:01:25 +08:00
"files": ["*.js"],
2018-09-29 09:40:19 +02:00
"options": {
"parser": "flow"
}
}
]
}
` ``
2020-06-28 03:47:29 +02:00
**Note:** _Never_ put the ` parser` option at the top level of your configuration. _Only_ use it inside ` overrides`. Otherwise you effectively disable Prettier’ s automatic file extension based parser inference. This forces Prettier to use the parser you specified for _all_ types of files – even when it doesn’ t make sense, such as trying to parse a CSS file as JavaScript.
2017-11-07 14:39:07 +11:00
## Configuration Schema
2025-11-18 00:19:50 +08:00
If you’ d like a JSON schema to validate your configuration, one is available here: [https://www.schemastore.org/prettierrc.json](https://www.schemastore.org/prettierrc.json).
2021-11-30 19:24:07 +00:00
## EditorConfig
2024-06-17 17:13:50 -06:00
If a [` .editorconfig` file](https://editorconfig.org/) is in your project, Prettier will parse it and convert its properties to the corresponding Prettier configuration. This configuration will be overridden by ` .prettierrc`, etc.
2021-11-30 19:24:07 +00:00
2025-10-12 16:46:24 +02:00
:::note
Unlike the EditorConfig spec, the search for ` .editorconfig` file will stop on the project root and won't proceed further.
:::
2022-05-02 12:37:05 -04:00
Here’ s an annotated description of how different properties map to Prettier’ s behavior:
2025-12-06 14:43:36 +08:00
` ``ini title=".editorconfig"
2022-05-02 12:37:05 -04:00
# Stop the editor from looking for .editorconfig files in the parent directories
# root = true
[*]
# Non-configurable Prettier behaviors
charset = utf-8
insert_final_newline = true
# Caveat: Prettier won’ t trim trailing whitespace inside template strings, but your editor might.
# trim_trailing_whitespace = true
# Configurable Prettier behaviors
# (change these if your Prettier config differs)
end_of_line = lf
indent_style = space
indent_size = 2
max_line_length = 80
` ``
Here’ s a copy+paste-ready ` .editorconfig` file if you use the default options:
2025-12-06 14:43:36 +08:00
` ``ini title=".editorconfig"
2022-05-02 12:37:05 -04:00
[*]
charset = utf-8
insert_final_newline = true
end_of_line = lf
indent_style = space
indent_size = 2
max_line_length = 80
` ``