Course contentsShow
← React
Lesson 78 of 2,3963. JSX FundamentalsFree lesson

JSX is Not HTML: Key Differences

Understanding that JSX is JavaScript with XML-like syntax, not actual HTML embedded in JS.

JSX is Not HTML: Key Differences

What you'll learn: Why JSX looks like HTML but behaves like JavaScript, and the subtle differences that matter.

It Looks Like HTML, But It's JavaScript

JSX might feel familiar if you know HTML, but it's actually JavaScript with an XML-like syntax. When you write what looks like <div>Hello</div>, you're really writing JavaScript code that will become React.createElement('div', null, 'Hello') after compilation.

Think of it this way: JSX is like a costume that makes JavaScript look like HTML. Underneath, it's pure JavaScript.

Key Differences You'll Encounter

JavaScript Reserved Words

Since JSX is JavaScript, you can't use JavaScript reserved words as attribute names:

  • HTML: class → JSX: className
  • HTML: for → JSX: htmlFor

camelCase Attribute Names

Event handlers and style properties use camelCase instead of kebab-case:

  • HTML: onclick → JSX: onClick
  • HTML: background-color → JSX: backgroundColor

Self-Closing Tags Must Close

In HTML, <img> or <input> can stay open. In JSX, they must close: <img /> or <input />

JavaScript Expressions Work Anywhere

You can embed JavaScript directly using curly braces: <div>{2 + 2}</div> outputs "4". HTML can't do that—it only understands text and tags.

Single Root Element

JSX expressions must return a single parent element. HTML doesn't have this restriction, but JSX needs it because it's ultimately returning one JavaScript value.

Key Takeaway: JSX is syntactic sugar for JavaScript function calls, not embedded HTML. It follows JavaScript rules with HTML-like appearance for familiarity.