Skip to content
IT glossary
FrontendUpdated December 3, 2026

JSX

A JavaScript syntax extension for describing user interfaces with HTML-like tags inside your code. It is most commonly used with React.

What JSX is

JSX lets you write the structure of a user interface next to the JavaScript that supplies its data. For example, <h1>{title}</h1> describes a heading whose text comes from the variable title. You can assign that expression to a variable, pass it to a function, or return it from a component. It looks like HTML, but it is neither an HTML string nor a DOM node.

What happens before rendering

JavaScript engines do not understand JSX as written. A tool such as Babel or SWC transforms it into standard JavaScript. With React's classic transform, <h1>{title}</h1> becomes React.createElement('h1', null, title). With the automatic transform, the generated code typically calls a helper from react/jsx-runtime instead. Either way, evaluating the expression produces a React element: a description of what to render. In the browser, React DOM uses that description to decide which DOM nodes to create or update.

Capitalization matters: <button> refers to a built-in element, while <SaveButton /> refers to a component in scope. Attributes supply props: label="Save" passes a string, while label={action.label} passes the value of a JavaScript expression.

Example

function SaveButton({ saving, onSave }) {
  return (
    <button type="button" disabled={saving} onClick={onSave}>
      {saving ? 'Saving…' : 'Save'}
    </button>
  );
}

The same saving prop controls both whether the button is disabled and which label it shows. onClick={onSave} passes a function for React to call when the button is clicked. Writing onClick={onSave()} would call the function during rendering and pass its return value instead.

Where it is used and what trips people up

JSX is common in React, Next.js, and React Native, but it is not exclusive to React. Other libraries can configure their toolchains to produce calls to a different runtime. TypeScript files that contain JSX use the .tsx extension.

  • Close every tag, including ones that HTML lets you leave open, such as <img />. In React DOM, write className rather than HTML's class.
  • Braces take expressions, not statements. Use a ternary to choose between two values, or put an if statement before the return.
  • When returning adjacent tags, group them into one expression. A fragment (<>...</>) does this without adding a wrapper to the DOM.

In an interview

You may be asked to render a list with map() and explain where the key goes. Put it on the outermost element returned for each item, and choose a stable value such as the item's ID. React uses keys to match siblings across renders. If the list can be reordered or filtered, an array index identifies a position rather than the item occupying it.