What is jsx

Last updated: April 1, 2026

Quick Answer: JSX is a syntax extension for JavaScript that allows you to write HTML-like markup directly in JavaScript code, primarily used with React to build user interface components.

Key Facts

Overview

JSX is a syntax extension for JavaScript that allows developers to write code that looks like HTML mixed with JavaScript. It makes component-based UI development more intuitive and readable. While it resembles HTML, JSX is actually syntactic sugar that gets converted into JavaScript function calls during the build process.

JSX Syntax

JSX looks like HTML but exists within JavaScript files. You can write tags like <div>, <button>, <Component /> directly in your JavaScript code. Custom components must start with a capital letter to distinguish them from HTML elements. Attributes can be passed like HTML attributes but use camelCase naming (className instead of class, onClick instead of onclick).

Embedding JavaScript

JSX allows you to embed JavaScript expressions inside markup using curly braces {}. This enables dynamic content, conditional rendering, and passing data to components. For example, {count} displays a variable value, {user ? 'Hello' : 'Login'} shows conditional text, and onClick={handleClick} attaches event handlers.

Compilation Process

JSX code cannot run directly in browsers. Build tools like Babel transform JSX into React.createElement() function calls. For instance, <div className='card'>Hello</div> becomes React.createElement('div', {className: 'card'}, 'Hello'). This transformation happens automatically during the build process, converting readable JSX into executable JavaScript.

Benefits and Adoption

JSX improves code readability by allowing developers to see UI structure more clearly. It reduces cognitive load by keeping markup and logic together in components. JSX has become the standard in React development and is adopted by other frameworks. While optional, JSX significantly improves developer experience and code maintainability in modern web development.

Related Questions

Do I need JSX to use React?

No, you can write React components using React.createElement() directly without JSX. However, JSX is more readable and is the standard approach used by most React developers and projects.

Do I need JSX to use React?

No, JSX is optional in React. You can write React components using React.createElement() directly without JSX syntax. However, JSX is the recommended and most widely-used approach in modern React development because it significantly improves code readability and developer experience.

How does JSX differ from regular HTML?

JSX is JavaScript syntax that looks like HTML but runs as code within JavaScript files. You can embed JavaScript expressions and logic inside JSX elements, while pure HTML is static markup without dynamic capabilities.

How does JSX get converted to JavaScript?

JSX is converted to JavaScript through a compilation process, typically using Babel transpiler. During the build process, JSX syntax like <Component /> is transformed into JavaScript function calls like React.createElement(Component). This conversion happens before the code runs in the browser.

What tools are needed to use JSX?

You need a build tool like Webpack, Vite, or Create React App that includes Babel transpiler to convert JSX into JavaScript. Without compilation, browsers cannot understand JSX syntax directly.

What's the difference between JSX and HTML?

While JSX looks similar to HTML, it's actually JavaScript that gets compiled into function calls. Key differences include using className instead of class, camelCase for attributes (onClick vs onclick), and embedding JavaScript expressions with curly braces. JSX integrates tightly with JavaScript logic.

Sources

  1. React - Introducing JSX CC-BY-4.0
  2. Wikipedia - React CC-BY-SA-4.0