Why HTML and JSX Are Different
When you start building with React, one of the first friction points is that JSX looks like HTML but isn't. Copy-paste a block of HTML from a design tool, a template, or a CMS preview, and React will throw errors. The syntax differences are small but mandatory.
Our HTML to JSX converter handles all the transformations automatically, so you can paste any HTML and get valid React code in seconds.
Key Differences: HTML vs JSX
class → className
class is a reserved word in JavaScript. JSX uses className for CSS classes.
<!-- HTML -->
<div class="container main">
<!-- JSX -->
<div className="container main">
for → htmlFor
Same reason — for is a JavaScript reserved keyword (for loops).
<label for="email"> → <label htmlFor="email">
Self-closing tags are mandatory
In HTML, <br>, <input>, <img> don't need closing. In JSX, every tag must be closed.
<input type="text"> → <input type="text" />
<br> → <br />
Inline styles become JavaScript objects
HTML inline styles are strings. JSX expects a JavaScript object with camelCased property names.
<!-- HTML -->
<div style="font-size: 14px; background-color: red;">
<!-- JSX -->
<div style={{ fontSize: '14px', backgroundColor: 'red' }}>
Event handlers use camelCase
onclick="handler()" → onClick={handler}
onchange="handler()" → onChange={handler}
tabindex → tabIndex
All HTML attributes that are two words are camelCased in JSX: tabIndex, readOnly, autoFocus, maxLength, colSpan, rowSpan, etc.
<!-- comments --> → {/* comments */}
HTML comments become JSX expression comments.
What Our Converter Handles
✅ class → className (all occurrences)
✅ for → htmlFor
✅ Self-closing all void elements (br, hr, img, input, link, meta, area, base, col, embed, param, source, track, wbr)
✅ Inline style string → JavaScript style object with camelCased properties
✅ HTML comments → JSX expression comments
✅ Event handler attribute names to camelCase
✅ Boolean attributes (disabled, checked, readonly → readOnly)
✅ tabindex → tabIndex, colspan → colSpan, etc.
Limitations
A few HTML patterns require manual attention after conversion:
- SVG attributes use camelCase in JSX (
strokeWidth, fillOpacity) — our tool handles most common ones
- **
data-* and ...
Looking for a more detailed deep-dive and advanced tips?
Read Full Article on our Blog