JSX is a JavaScript syntax extension that describes a React element tree. Expressions inside braces are evaluated as JavaScript values, while lowercase names describe host elements and capitalized names refer to components.
Use JSX to make structure and data flow readable, not to hide large calculations. Keep expressions pure, provide stable keys for repeated siblings, map HTML differences such as className correctly, and remember that JSX is transformed before the browser executes it.
JSX stands for JavaScript XML. It is the syntax React uses to describe the user interface in a way that looks similar to HTML, while still being written inside JavaScript.
JSX makes React code easier to read because the structure of the UI appears directly inside the component. Build tools such as Babel or Vite convert JSX into regular JavaScript before the browser runs it.
function Welcome() {
const name = 'Aman'
return (
<div className="welcome-box">
<h1>Hello, {name}!</h1>
<p>Welcome to React JSX.</p>
</div>
)
}
export default Welcome
// JSX version
const element = <h1 className="title">Hello, World!</h1>
// React converts it into JavaScript
const element = React.createElement(
'h1',
{ className: 'title' },
'Hello, World!'
)
Writing UI with plain React.createElement() becomes difficult to read as the layout grows. JSX keeps the code more natural and closer to the final structure of the page.
JSX also works very well with JavaScript expressions. You can show variables, call methods, render content conditionally, and create lists directly inside the markup.
You can use JavaScript expressions inside JSX by wrapping them in curly braces {}. This is one of the most important ideas in React.
function Profile() {
const user = 'Sara'
const age = 22
return (
<div>
<h2>User: {user}</h2>
<p>Age: {age}</p>
<p>Next year age: {age + 1}</p>
<p>Uppercase name: {user.toUpperCase()}</p>
</div>
)
}
JSX looks like HTML, but it follows a few React-specific rules.
function FormExample() {
return (
<form className="login-form">
<label htmlFor="email">Email</label>
<input id="email" type="email" />
<br />
<button onClick={() => alert('Submitted')}>
Submit
</button>
</form>
)
}
JSX can render different output based on conditions. The most common approaches are the ternary operator and the logical && operator.
function LoginStatus() {
const isLoggedIn = true
return (
<div>
{isLoggedIn ? <p>Welcome back!</p> : <p>Please log in.</p>}
{isLoggedIn && <button>Logout</button>}
</div>
)
}
JSX is often used to render repeated content such as menu items, products, or users. In React, this is commonly done with map().
When rendering lists, always use a unique key prop. Keys help React identify which items changed, were added, or were removed.
function DynamicJSX() {
const fruits = ['Apple', 'Banana', 'Cherry']
const isActive = true
return (
<div>
<ul>
{fruits.map((fruit) => (
<li key={fruit}>{fruit}</li>
))}
</ul>
<div className={`card ${isActive ? 'active' : 'inactive'}`}>
Status: {isActive ? 'Active' : 'Inactive'}
</div>
</div>
)
}
If you want to return multiple elements without adding an extra wrapper element like div, use a fragment.
function PageTitle() {
return (
<>
<h1>React Course</h1>
<p>Learn JSX step by step.</p>
</>
)
}
JSX is the syntax React uses to describe the UI. It looks like HTML, but it is really JavaScript with a few special rules. Once you understand expressions, conditions, lists, and fragments, JSX becomes a natural way to build React components.
Explore 500+ free tutorials across 20+ languages and frameworks.