React JSX (JavaScript XML) is a syntax extension that lets you write HTML-like tags directly inside JavaScript functions. Browsers cannot run JSX natively, so build tools like Babel, SWC, or Vite compile every JSX tag into standard JavaScript function calls before shipping code.
When Vite builds your component, each JSX element becomes a jsx() runtime call (or React.createElement() in older setups). That call returns a plain JavaScript object describing the element type, props, and children.
// JSX source code
const heading = <h2 className="title">Welcome Back</h2>;
// Compiled JavaScript output
const compiled = React.createElement('h2', { className: 'title' }, 'Welcome Back');
<>...</>). Returning two adjacent tags without a wrapper throws a syntax error.<br />, <hr />, and <input type="text" /> must end with a forward slash in JSX.class becomes className, for becomes htmlFor, and tabindex becomes tabIndex.{ ... }. Statements such as for loops or if blocks are not allowed inside {}.export function UserSummary({ user, unreadCount }) {
const statusColor = user.isOnline ? '#16a34a' : '#64748b';
return (
<article className="user-summary">
<h2>{user.fullName}</h2>
<p style={{ color: statusColor }}>
Unread alerts: {unreadCount}
</p>
<label htmlFor="quick-note">Quick note</label>
<input id="quick-note" type="text" placeholder="Type here..." />
</article>
);
}
style="color: red" crashes in React because style expects a JavaScript object (style={{ color: 'red' }}).{user} inside JSX throws an "Objects are not valid as a React child" error. Render {user.name} instead.No, you can call React.createElement manually, but JSX is the industry standard because nested UI trees stay readable.
React escapes all string values embedded inside {expression} braces before inserting them into the DOM, preventing injected script execution.
Yes. Wrap comments in curly braces using block comment syntax: {/* Comment inside JSX */}.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With