React
frontendreactGuideBeginner
JSX (JavaScript XML) Syntax Guide
Mastering JSX: syntax rules, embedding JavaScript expressions with curly braces {}, Fragments, className, and style objects.
Verified: 2026-09-30
Tested on:react 19.x
Platforms:
web
#react#jsx#syntax#fragments
JSX (JavaScript XML) Syntax Guide
JSX is a syntax extension for JavaScript that lets you write HTML-like markup directly inside a JavaScript/TypeScript file.
1. Core JSX Syntax Rules
- Return a Single Root Element (Use Fragments
<>...</>):return ( <> <h1>OpenDevDocs</h1> <p>Learn. Build. Debug. Deploy.</p> </> ); - Close All Tags Explicitly: Self-closing tags must end with
/>(e.g.<img src="..." alt="" />,<input />,<br />). - CamelCase Property Names:
classbecomesclassNameforbecomeshtmlFortabindexbecomestabIndexonclickbecomesonClick
2. Embedding JavaScript Expressions with {}
Any valid JavaScript expression (variables, function calls, arithmetic, ternary conditions) can be embedded inside JSX using curly braces {}:
export function Greeting({ username }: { username: string }) {
const isMorning = new Date().getHours() < 12;
return (
<div className="banner">
<h2>Good {isMorning ? "Morning" : "Evening"}, {username.toUpperCase()}!</h2>
<p>Active issues: {10 + 4}</p>
</div>
);
}Related Topics
React Components & Function Architecture
Building React components: functional components, return requirements, PascalCase naming, component purity, and folder organization.
React Props and Component Interfaces
Passing data to React components via props: destructuring, default values, children prop, callbacks, and typing props with TypeScript.