HTML to JSX: the differences that break copy-paste
JSX looks like HTML, which is exactly why pasting markup into a React component seems like it should work. Most of the time it almost does. The failures come from a small set of deliberate differences: reserved words, attribute casing, self-closing tags, style objects and event handlers.
Four changes you hit immediately
Start with markup copied from a browser or a design tool. It is valid HTML and invalid JSX in four places.
<section class="card">
<label for="email">Email</label>
<img src="/logo.png" alt="Logo">
</section>In JSX, class becomes className and for becomes htmlFor, because both are reserved words in JavaScript. Void elements such as <img>, <br> and <input> must close with />. Those are not style preferences; they are syntax.
<section className="card">
<label htmlFor="email">Email</label>
<img src="/logo.png" alt="Logo" />
</section>Inline styles are objects, not strings
An HTML style attribute is a CSS string. JSX wants an object with camelCased property names. Values that need units stay strings, while unitless properties such as z-index, opacity and line-height become numbers.
<div style="font-size: 14px; z-index: 2">Hi</div><div style={{ fontSize: "14px", zIndex: 2 }}>Hi</div>Event handlers are functions
An inline onclick holds a string that the browser evaluates. React expects a function, so the string has to be rewritten. Inside that function, this no longer means the element — use event.currentTarget. Returning false no longer cancels the event either; call event.preventDefault() instead.
<button onclick="save(this)">Save</button><button onClick={(event) => save(event.currentTarget)}>Save</button>SVG has its own naming rules
SVG attributes such as stroke-width, fill-rule and xlink:href use a different casing convention, and React only accepts the camelCased form. Element names like linearGradient are case-sensitive too, so lowercased markup from an SVG editor needs restoring. Icons often hard-code a fill color as well; currentColor lets them follow the surrounding text instead.
<svg viewBox="0 0 24 24"><path stroke-width="2" fill="#000" d="M12 5v14M5 12h14"/></svg><svg viewBox="0 0 24 24">
<path strokeWidth={2} fill="currentColor" d="M12 5v14M5 12h14" />
</svg>The quiet fixes worth knowing
- Bare table rows are wrapped in <tbody>, because React warns when a browser inserts one and the markup does not.
- <option selected> moves to the parent <select> as defaultValue, and value/checked become defaultValue/defaultChecked so the field stays uncontrolled.
- Comments become {/* … */}. Text that contains braces is escaped so it renders literally.
- HTML5 entities that JSX does not decode are converted; the XHTML entities JSX already understands are left alone.
- Unclosed <p>, <li> and <td> tags are closed the way a browser would, and numeric attributes such as tabindex become numbers.
What no converter should decide for you
The syntax is mechanical; the design is not. A converter can turn markup into valid JSX, but it cannot know whether a click handler belongs in the component, which values should become props, or whether a list needs stable keys. Keep the component boundary, state and accessibility decisions in your hands — and read the warnings, which are there for exactly the cases that need a human.
Paste the markup and get the JSX, with every rewrite listed in a table you can audit.
Open the HTML to JSX converter