JSX vs HTML

Last updated: 2026-11-02

JSX vs HTML JSX vs HTML

JSX looks like HTML, but a few rules differ: attributes use lower camel case, class becomes className, style takes an object, and every tag must be closed. Learning these differences up front saves you from the compile errors that trip up most React beginners, and it makes existing HTML snippets easy to translate.

GroupCore Concepts
KindReference
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

<div className="box" style={{ fontSize: 14 }}>
//     ↑ class becomes className   ↑ style is an object with camelCase keys
  <img src="a.png" />        {/* Void elements must be self-closed */}
  <label htmlFor="mail">Email</label>  {/* for becomes htmlFor */}
</div>

Returns:No return value — a coding convention and mental model.

▶ Example

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

Output:

A bordered, rounded card holding a heading, an "Email" label, a placeholder input and one line of red explanatory text — all rendered with JSX camelCase attributes and an object style.

💡 Key Points

⚠️ Warning Writing class fails to compile outright — you must use className; style={{}} is an object literal, hence the double braces.
💡 Tip Void elements such as img, br and input must be self-closed in JSX: <img />, or the build fails.
ℹ️ Info Most other attributes just switch to lower camel case: onclick → onClick, tabindex → tabIndex. The semantics do not change.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q Why does JSX use className instead of class?
A Because JSX is part of JavaScript and class is a reserved word in the language, so React picked className to match element.className in the DOM API.
Q How do I write style in JSX?
A style takes an object rather than a string: style={{ fontSize: 14, color: 'red' }}. Keys use lower camel case and numbers are treated as pixels automatically.
Q Can JSX tags stay unclosed?
A No. Strict XML-style closing is a JSX rule — <img>, <br> and <input> all have to be written in self-closing form.
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%

🙏 帮我们做得更好

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

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