| | |

Prettier 08 ๐ŸŽจ JSX Formatting โ€” jsxBracketSameLine and JSX-specific behavior

โฑ๏ธ Estimated read: 9 min | |

JSX is not HTML, and it is not JavaScript. It is its own syntax with its own formatting rules. Prettier treats it accordingly: it wraps JSX in parentheses in return statements, it preserves double quotes for JSX attributes even when singleQuote is true for JavaScript, and it places the closing > of a multi-line tag according to a dedicated option. The jsxBracketSameLine option controlled that placement, but it was deprecated in Prettier 2.4 and replaced by the broader bracketSameLine option, which also covers HTML, Vue, and Angular .

This chapter covers the bracketSameLine option (and its deprecated jsxBracketSameLine predecessor), the JSX-specific formatting that Prettier applies regardless of configuration, and the jsxSingleQuote option that decouples JSX attribute quotes from the rest of the file.

Key point: jsxBracketSameLine is deprecated. Use bracketSameLine instead. It controls whether the > of a multi-line tag sits on the last line or on its own line, and it applies to JSX, HTML, Vue, and Angular alike.


Why JSX formatting has its own rules

The HTML heritage problem. JSX was designed to look like HTML. HTML attributes are conventionally written with double quotes, and browser developer tools display them with double quotes regardless of the source. Prettier follows this convention: singleQuote: true changes JavaScript strings to single quotes, but JSX attributes remain double-quoted unless jsxSingleQuote is set separately . The two quote styles can coexist in the same file because they serve different syntactic purposes.

The semicolon problem. In JavaScript, a stray semicolon after a statement is harmless. In JSX, a stray semicolon inside the markup can end up as plain text on the page. Prettier wraps JSX in parentheses in return statements partly to make the boundaries explicit and reduce the chance of leaving a semicolon behind . The parentheses are not required by JSX, but they make the formatted output safer to edit.

The tag-close problem. A multi-line JSX element has two valid shapes for its closing angle bracket. It can sit on the last attribute’s line, or it can sit alone on the next line. The choice is visual, but it affects the diff when a new attribute is added. The option that controls this was originally named jsxBracketSameLine and later renamed to bracketSameLine when the same behavior was extended to HTML, Vue, and Angular .


a. The bracketSameLine option

The option is a boolean. false places the > on its own line; true places it on the last line of the tag.

{
  "bracketSameLine": false
}

With false, the default, a multi-line JSX element closes like this:

<button
  type="button"
  onClick={handleClick}
>
  Click
</button>

The > is on its own line, aligned with the opening <. This is the Prettier default and the form that many teams adopt because it makes the tag boundaries visually distinct.

With true, the > moves to the last attribute’s line:

<button
  type="button"
  onClick={handleClick}>
  Click
</button>

The option was introduced as jsxBracketSameLine in early Prettier versions and renamed to bracketSameLine in Prettier 2.4 . The old name is deprecated. A project still using jsxBracketSameLine in its configuration is using a deprecated key; the behavior is the same, but the key may be removed in a future major version. The React repository itself updated its .prettierrc to replace the deprecated key .


b. JSX-specific formatting that is not configurable

Several JSX formatting behaviors are not controlled by an option. They are part of Prettier’s core handling of the syntax.

Parentheses around JSX in return. A return statement that returns JSX is wrapped in parentheses, even if the JSX is a single element. This is a deliberate choice: it matches the style that many developers already used, and it makes the boundaries of the returned expression explicit .

function Greeting() {
  return (
    <div>
      <h1>Hello</h1>
    </div>
  )
}

The parentheses are always added. They are not optional, and no configuration removes them.

Double quotes for JSX attributes. The singleQuote option applies to JavaScript strings. JSX attributes remain double-quoted unless jsxSingleQuote is set to true. The rationale is the HTML heritage: HTML attributes are conventionally double-quoted, and JSX follows that convention by default .

Escape preservation. Prettier maintains the way a string is escaped. A Unicode character written as an escape sequence is not converted to the literal character, and vice versa. This applies to JSX attributes as well as JavaScript strings .


c. The jsxSingleQuote option

The jsxSingleQuote option is separate from singleQuote. It controls only the quotes of JSX attributes.

{
  "singleQuote": true,
  "jsxSingleQuote": true
}

With both options set, JavaScript strings and JSX attributes both use single quotes. With only singleQuote set, JavaScript strings use single quotes and JSX attributes remain double-quoted. The two options are independent because the two contexts have different conventions .

A team that wants a uniform single-quote style across the entire file must set both options. A team that wants JavaScript single quotes and HTML-style double quotes in JSX sets only singleQuote.


Complete Example Session

// ============================================
// PART 1: THE CONFIGURATION
// ============================================
{
  "bracketSameLine": false
}
// ============================================
// PART 2: bracketSameLine: false (DEFAULT)
// ============================================
<button
  type="button"
  onClick={handleClick}
>
  Click
</button>
// ============================================
// PART 3: bracketSameLine: true
// ============================================
{
  "bracketSameLine": true
}
// ============================================
// PART 4: bracketSameLine: true OUTPUT
// ============================================
<button
  type="button"
  onClick={handleClick}>
  Click
</button>
// ============================================
// PART 5: THE DEPRECATED OPTION
// ============================================
{
  "jsxBracketSameLine": true
}

// Deprecated since Prettier 2.4.
// Use bracketSameLine instead.
// ============================================
// PART 6: JSX PARENTHESES IN RETURN
// ============================================
function Greeting() {
  return (
    <div>
      <h1>Hello</h1>
    </div>
  )
}

// The parentheses are always added.
// They are not configurable.
// ============================================
// PART 7: QUOTE SEPARATION
// ============================================
{
  "singleQuote": true
}
// ============================================
// PART 8: SINGLE QUOTES IN JS, DOUBLE IN JSX
// ============================================
const message = 'Hello'

// JSX attribute remains double-quoted
<div className="container" />
// ============================================
// PART 9: jsxSingleQuote
// ============================================
{
  "singleQuote": true,
  "jsxSingleQuote": true
}
// ============================================
// PART 10: UNIFORM SINGLE QUOTES
// ============================================
const message = 'Hello'

// JSX attribute now uses single quotes
<div className='container' />

The ten parts covered the default false, the true value, the deprecated jsxBracketSameLine, JSX parentheses, quote separation, and jsxSingleQuote.


Quick Reference

bracketSameLine

ValueOutputDefault
false> on its own lineYes
true> on the last attribute lineNo
Deprecated namejsxBracketSameLineReplaced in 2.4

JSX-specific options

OptionScopeDefault
bracketSameLineJSX, HTML, Vue, Angularfalse
jsxSingleQuoteJSX attributes onlyfalse
singleQuoteJavaScript stringsfalse

Non-configurable JSX behavior

BehaviorDetail
Parentheses in returnAlways added
Attribute quotesDouble by default
Escape sequencesPreserved

Best Practices

โœ… Do This:

// Use bracketSameLine, not jsxBracketSameLine
{ "bracketSameLine": true }                                 // โœ…
// Set jsxSingleQuote separately if single quotes are wanted in JSX
{ "singleQuote": true, "jsxSingleQuote": true }             // โœ…
// Let Prettier add the parentheses in return
return (
  <div />
)                                                          // โœ…

โŒ Don’t Do This:

// Use the deprecated option name
{ "jsxBracketSameLine": true }                              // โŒ
// Assume singleQuote affects JSX attributes
{ "singleQuote": true }  // JSX attributes stay double       // โŒ
// Write JSX in return without parentheses and expect Prettier to keep it
return <div />  // Prettier adds parentheses                 // โŒ

Common Pitfalls

PitfallWhy It HappensFix
Configuration key is deprecatedjsxBracketSameLine still works but is deprecatedRename to bracketSameLine
JSX attributes still double-quotedsingleQuote does not apply to JSXSet jsxSingleQuote: true
Parentheses appear unexpectedlyPrettier always wraps JSX in returnAccept the behavior; it is not configurable
bracketSameLine affects HTMLIt is the intended scopeThe option covers HTML, Vue, and Angular

Real-World Examples

1. Default bracketSameLine

<button
  type="button"
>

2. bracketSameLine: true

<button
  type="button">

3. Deprecated key

{ "jsxBracketSameLine": true }

4. JSX parentheses

return (
  <div />
)

5. Double quotes in JSX

<div className="container" />

6. jsxSingleQuote

{ "jsxSingleQuote": true }

7. Single quotes in JSX

<div className='container' />

8. Escape preservation

<div title="๐Ÿ™‚" />

9. The rename

jsxBracketSameLine โ†’ bracketSameLine (Prettier 2.4)

10. The scope

bracketSameLine applies to JSX, HTML, Vue, Angular.

Visual

bracketSameLine

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  false (default)              true                           โ”‚
โ”‚                                                              โ”‚
โ”‚  <button                      <button                        โ”‚
โ”‚    type="button"                type="button"                โ”‚
โ”‚    onClick={fn}                 onClick={fn}>                โ”‚
โ”‚  >                                                           โ”‚
โ”‚    Click                        Click                        โ”‚
โ”‚  </button>                    </button>                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The quote separation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  singleQuote: true, jsxSingleQuote: false                    โ”‚
โ”‚                                                              โ”‚
โ”‚  const x = 'hello'         โ† single quote (JS)              โ”‚
โ”‚  <div className="x" />      โ† double quote (JSX)            โ”‚
โ”‚                                                              โ”‚
โ”‚  singleQuote: true, jsxSingleQuote: true                     โ”‚
โ”‚                                                              โ”‚
โ”‚  const x = 'hello'         โ† single quote                   โ”‚
โ”‚  <div className='x' />      โ† single quote                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The deprecated rename

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Prettier < 2.4: jsxBracketSameLine                          โ”‚
โ”‚  Prettier 2.4+:  bracketSameLine                             โ”‚
โ”‚                                                              โ”‚
โ”‚  The old key still works but is deprecated.                  โ”‚
โ”‚  The new key also covers HTML, Vue, Angular.                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

JSX in return

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Prettier always adds parentheses:                           โ”‚
โ”‚                                                              โ”‚
โ”‚  return (                                                    โ”‚
โ”‚    <div />                                                   โ”‚
โ”‚  )                                                           โ”‚
โ”‚                                                              โ”‚
โ”‚  The parentheses are not configurable.                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
OptionbracketSameLine
Deprecated namejsxBracketSameLine
Defaultfalse
false behavior> on its own line
true behavior> on the last attribute line
ScopeJSX, HTML, Vue, Angular
JSX attribute quotesControlled by jsxSingleQuote
JSX in returnAlways wrapped in parentheses

Key takeaways:

  • jsxBracketSameLine is deprecated. It was renamed to bracketSameLine in Prettier 2.4, and the new name extends the same behavior to HTML, Vue, and Angular . The old key still works, but it should be replaced.
  • The option controls the closing > placement. With false (the default), the > sits on its own line. With true, it sits on the last attribute’s line. The choice is visual and affects the diff when an attribute is added.
  • JSX attributes are double-quoted by default, even with singleQuote: true. The jsxSingleQuote option is the separate switch for JSX attribute quotes. The two options are independent because JavaScript strings and HTML-style attributes have different conventions .
  • Prettier always wraps JSX in parentheses in return statements. This is not configurable. It matches common practice and reduces the risk of a stray semicolon appearing as page text .
  • The JSX formatting rules exist because JSX is neither JavaScript nor HTML. The parentheses and the quote separation are deliberate choices that reflect the syntax’s hybrid nature, not arbitrary style preferences.

Remember: jsxBracketSameLine is a deprecated name for bracketSameLine. Use the new key. The option controls where the closing > sits on a multi-line tag, and it applies to JSX, HTML, Vue, and Angular. JSX attributes are double-quoted by default; jsxSingleQuote is the option that changes them. Prettier always wraps JSX in parentheses in return statements, and that behavior is not configurable. The JSX rules are not arbitraryโ€”they exist because JSX borrowed HTML’s conventions while living inside JavaScript’s syntax.

Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!