Skip to content
Tutorials Center
My learning

Topics

React Reference ยท JSX Syntax and Rules

Short fragment syntax

Reference for the short fragment syntax <></> in JSX: group siblings without a wrapper node, what the shorthand cannot do, and when to use the long Fragment form.

A JSX expression must have exactly one root. When a component needs to return several siblings, you could wrap them in a <div>, but that adds a node to the DOM that you may not want: a stray <div> inside a <table>, <ul> or a flex container changes the layout or even makes the HTML invalid.

The short fragment syntax <>...</> is the lightest solution. It groups any number of children into a single JSX expression, and React renders only the children. The compiler turns <>...</> into the same thing as <Fragment>...</Fragment>; the short form is just shorter to type and needs no import.

JSX
function Term({ word, meaning }) {
  return (
    <>
      <dt>{word}</dt>
      <dd>{meaning}</dd>
    </>
  );
}

Try it

Siblings inside a description list
Where the short form stops

Syntax

JSX
<>
  {children}
</>
Part Description
<> ... </> An opening and a closing tag with no name and no attributes.
Children Any elements, text, expressions and arrays.

Returns: a fragment element. It has no DOM node and no instance.

Limits: the short form cannot take any attribute, which means no key, and nothing else. For a key, write <Fragment key={id}> and import Fragment from react. <></> with no children is valid and renders nothing.

Usage notes

  • Same behavior as Fragment. The compiler converts <> to Fragment (from react/jsx-runtime, or React.Fragment in the classic transform). The tree React sees is identical.
  • Classic transform. With the older createElement transform, the shorthand requires React to be in scope, unless you configure a different jsxFragmentFactory. The TryIt examples and modern toolchains need no import.
  • Needed in lists. An item that returns several siblings inside .map() needs the keyed long form. See Keyed fragments.
  • State positions. Moving children into or out of a fragment at the same position does not reset their state; changing how deep they are nested does.
  • Use a real element when it adds meaning. If the group should be a <section>, <ul> or a styling hook, write the element. A fragment is for hiding structure from the DOM, not from the reader.
  • Comments and whitespace. A {/* comment */} is allowed inside a fragment. Text lines are trimmed as in any other JSX; see JSX whitespace.
  • No ref. A fragment is not a DOM node, so you cannot attach a ref to it in a stable release.
  • Formatting tools. Prettier and ESLint understand <>. Some older syntax highlighters do not; they are not a sign of an error.