JSX JSX Syntax

Last updated: 2026-11-02

JSX JSX Syntax

JSX is a syntax extension for JavaScript that lets you write interface markup directly inside a JS file. It is compiled into ordinary function calls that describe what the screen should look like for the current state. Every React component renders through JSX, so mastering its syntax is the first step toward writing components that stay readable as they grow in complexity.

GroupCore Concepts
KindPattern
SinceEarliest React versions

ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.

📝 Syntax

const el = <h1 className="title">Hello, {name}</h1>
//         ↑ tag     ↑ camelCase prop       ↑ any JS expression goes inside {}

Returns:No return value — JSX is a convention and mental model: after compilation it is a plain JS expression whose value describes the interface.

▶ Example

The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.

Output:

The page shows the heading "Hello, React Learner!", a line reading "Role: Admin" and a text input; typing in the input updates the name in the heading in real time.

💡 Key Points

💡 Tip Write class as className and for as htmlFor — class and for are reserved words in JavaScript.
ℹ️ Info Inside {} you can only write expressions (variables, operators, ternaries, function calls), never if or for statements.
⚠️ Warning JSX must have exactly one root element; wrap sibling nodes in a <div> or a <Fragment>.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q What is JSX? Is it HTML?
A No. JSX is a syntax extension of JavaScript that compiles into function calls; it only looks like HTML so that the structure of an interface stays readable.
Q How do I write comments in JSX?
A Wrap a block comment in braces: {/* comment */}. When it sits in the children position, this is the only form that works.
Q How do I write if-else inside JSX?
A Only expressions fit inside braces: use the ternary operator condition ? A : B, or prepare a variable with a plain if before the return.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏