singleQuotea preference Prettier overrides whenever escaping would suffer

The Prettier Single Quote option

singleQuote states which quote character you prefer for JavaScript strings. It is a preference rather than a rule: Prettier always picks the quote that produces fewer escape sequences, so a string containing an apostrophe stays double-quoted even with singleQuote: true.

Use single quotes instead of double quotes.
Prettier's own description, from the official options documentation
Default
false
Type
boolean
CLI flag
--single-quote

What the option does

The default is false, meaning double quotes. Set it to true and Prettier prefers single quotes — but only as a tie-break.

The rule Prettier actually applies is quote minimisation: whichever quote character requires fewer backslash escapes wins, and your preference decides only when the count is equal. This is why a codebase with singleQuote: true still contains double-quoted strings, and why that is correct rather than a bug:

const plain = 'no quotes inside';
const apostrophe = "it's got one";
Both lines are what singleQuote: true produces.

Escaping the apostrophe to keep the single quotes would produce 'it\'s got one', which is one character longer and materially harder to read. Prettier declines.

What it does not touch

  • JSON and JSON-like files. The format only permits double quotes, so the option is ignored there — including the prettier key in package.json.
  • JSX attributes. Those have their own option, jsxSingleQuote, because the prevailing convention in JSX markup differs from the one in surrounding JavaScript.
  • Template literals. Backtick strings are never rewritten to quotes, since that could change behaviour.
  • Object keys. Whether a key is quoted at all is quoteProps; this option only picks which character is used once something is being quoted.

Why the default is double quotes

Double quotes are the default largely because they are the safer of the two in English-language content. Apostrophes are common in prose, and user-facing strings are prose more often than not, so double quotes minimise escaping across a typical codebase without anyone having to think about it.

They also match JSON, which means a string copied between a JavaScript file and a JSON file needs no adjustment. Given how much configuration moves between those two formats, that is a small but real convenience.

The counter-argument is habit rather than logic: a large share of the JavaScript ecosystem writes single quotes, and matching it makes your code look ordinary to a contributor arriving from elsewhere. Neither position is wrong, which is exactly why this is an option.

Trade-offs and team conventions

This is the cheapest option in Prettier to change and the one least worth arguing about. It has no correctness implications, no performance implications, and no effect on tooling. Pick one in the first week of a project and never revisit it.

  • If the project is TypeScript-first and modern, singleQuote: true matches the majority of what your contributors will have seen.
  • If the project ships a lot of user-facing English text, the default saves you escapes.
  • Whichever you pick, expect exceptions in the output. A reviewer who flags a double-quoted string in a single-quote codebase has misunderstood the option, not found a defect.

ESLint and editors

ESLint's quotes rule overlaps directly with this option and will fight it, most visibly on the escape-minimisation cases above. eslint-config-prettier disables quotes along with the rest of the stylistic set; put it last in your config.

{
  "singleQuote": true,
  "jsxSingleQuote": false
}
The two settings that usually travel together.

That pairing — single quotes in JavaScript, double quotes in JSX — is the most common configuration in React codebases, because JSX attributes read like HTML and HTML attributes are conventionally double-quoted.

Common mistakes

  • Reporting the escape-minimisation behaviour as a bug. It is the documented and intended rule.
  • Expecting it to change JSX attributes. That is jsxSingleQuote.
  • Expecting it to change JSON. The format forbids single quotes.
  • Leaving ESLint’s quotes rule on, which produces a lint error Prettier will immediately re-create on the next format.

Use it in .prettierrc

Drop singleQuote into your Prettier config file:

{
  "singleQuote": false
}
Try it in the generator

Worked examples

The same code formatted with each value of singleQuote.

singleQuote: true

const user = {
  name: 'Ada',
  'user-id': 7,
  roles: ['admin', 'editor'],
  active: true,
};
const greet = (name) => `Hello ${name}`;
const label = user.active
  ? 'active member of the team'
  : 'inactive member of the team';
export function summarize(items) {
  return items
    .filter((i) => i.active)
    .map((i) => i.name)
    .join(', ');
}

singleQuote: false

const user = {
  name: "Ada",
  "user-id": 7,
  roles: ["admin", "editor"],
  active: true,
};
const greet = (name) => `Hello ${name}`;
const label = user.active
  ? "active member of the team"
  : "inactive member of the team";
export function summarize(items) {
  return items
    .filter((i) => i.active)
    .map((i) => i.name)
    .join(", ");
}

Common questions

Why is this string still double-quoted with singleQuote enabled?
Because it contains an apostrophe or a single quote. Prettier chooses whichever quote character needs fewer escapes and only falls back to your preference on a tie.
Does singleQuote affect JSX?
No. JSX attribute quoting is controlled by jsxSingleQuote, which defaults to false so that JSX keeps the double quotes conventional in HTML.
Does it affect JSON or package.json?
No. JSON permits only double quotes, so Prettier leaves them alone regardless of this setting.

Other Common options

Generated from Prettier 3.9.6.