JSX lets you write React components with markup that looks like HTML. But it's JavaScript underneath: <div className="card"> compiles to a function call such as jsx("div", { className: "card" }). Every difference from HTML follows from that, and knowing the list saves time when you paste a template into a component.
Attribute names
className and htmlFor
class and for are reserved words in JavaScript, so JSX uses the DOM property names:
<label for="email" class="label">Email</label>
<label htmlFor="email" className="label">Email</label>
camelCase attributes
Multi-word attributes use camelCase, matching DOM properties: tabIndex, readOnly, maxLength, colSpan, autoComplete, crossOrigin, srcSet, contentEditable, spellCheck.
The exceptions are data-* and aria-*, which stay exactly as in HTML.
Event handlers
HTML event attributes are strings of code. In JSX they're camelCase props that take a function:
<button onclick="save()">Save</button>
<button onClick={save}>Save</button>
<button onClick={() => save(item.id)}>Save</button>
Pass the function, don't call it: onClick={save()} runs save during every render.
Inline styles are objects
<div style="background-color: #f5f5f5; margin-top: 8px; --gap: 4px"></div>
<div style={{ backgroundColor: "#f5f5f5", marginTop: 8, "--gap": "4px" }}></div>
- Property names are camelCase; custom properties keep their
--name as a string key. - Numbers get
pxadded for most length properties (marginTop: 8). Unitless properties likelineHeight,opacityandzIndexstay as numbers. - Vendor prefixes start with a capital letter:
WebkitLineClamp.msprefixes are the exception (msTransform).
The double braces are just a JavaScript object inside a JSX expression.
Every tag must be closed
HTML allows void elements without a closing slash. JSX requires one:
<img src="logo.png" alt="Logo">
<br>
<input type="text" name="q">
<img src="logo.png" alt="Logo" />
<br />
<input type="text" name="q" />
Any element without children can self-close in JSX, including <div />.
Comments
HTML comments are a syntax error inside JSX. Use a JavaScript comment inside braces:
{/* This is a comment */}
Boolean attributes
In HTML, the presence of an attribute makes it true. In JSX, pass a boolean:
<input disabled /> // true
<input disabled={isSaving} /> // depends on the value
<input disabled={false} /> // not disabled (in HTML, disabled="false" is still disabled)
Form elements
React treats form values differently:
valueandcheckedmake an input controlled: React owns the value, so you need anonChangehandler. For an initial value only, usedefaultValueordefaultChecked.<textarea>takes its content fromvalueordefaultValue, not from children.<select>usesvalueon the<select>itself instead ofselectedon an<option>.
<select value={country} onChange={(e) => setCountry(e.target.value)}>
<option value="in">India</option>
<option value="us">United States</option>
</select>
Text and special characters
Text in JSX is escaped automatically, which protects against injection; see escaping HTML. HTML entities like and © work in JSX text, but { and } must be written as {"{"} and {"}"} because braces start expressions.
Whitespace differs too: JSX removes line breaks and indentation between lines. Add an explicit {" "} when you need a space between an element and text on the next line.
Inline SVG
SVG pasted into JSX needs the same treatment, plus a few SVG-specific attributes:
| SVG | JSX |
|---|---|
stroke-width |
strokeWidth |
fill-rule, clip-rule |
fillRule, clipRule |
stroke-linecap |
strokeLinecap |
xlink:href |
xlinkHref (or plain href in modern SVG) |
class |
className |
style="..." |
style={{ ... }} |
viewBox keeps its camelCase from SVG. Remove xmlns:xlink declarations if you no longer use xlink.
Things that don't carry over
- Inline
<script>tags inside components don't run when React inserts them on the client. Load scripts with your framework's script component, an effect, or (in React 19) anasyncscript with asrc. - Inline event code like
onclick="..."must become a function. <!DOCTYPE>,<html>and<head>belong to your framework's document or layout, not to components.
Quick reference
| HTML | JSX |
|---|---|
class="x" |
className="x" |
for="id" |
htmlFor="id" |
tabindex="0" |
tabIndex={0} |
onclick="f()" |
onClick={f} |
style="color: red" |
style={{ color: "red" }} |
<br> |
<br /> |
<!-- note --> |
{/* note */} |
disabled |
disabled or disabled={true} |
<option selected> |
<select value=...> |
<textarea>text</textarea> |
<textarea defaultValue="text" /> |