You have a working HTML template: a landing page from a designer, a snippet from a UI kit, or an old page you are rebuilding in React. You paste it into a component and the build fails with a string of errors, or it compiles and then React fills the console with warnings about class, for and uncontrolled inputs. JSX looks almost exactly like HTML, and that "almost" is where the trouble lives.
This guide explains why JSX differs from HTML, lists the specific changes that every conversion needs, covers form inputs and event handlers where conversions often go wrong, and shows how to convert markup quickly and then finish the job by hand.
Why JSX is not HTML
JSX is a syntax extension for JavaScript. A build tool compiles each JSX element into a function call that creates a React element. In the classic transform:
<h1 className="title">Hello</h1>
compiles roughly to:
React.createElement("h1", { className: "title" }, "Hello");
Newer projects use an automatic runtime that calls a different function, but the idea is the same. Attributes become properties of a JavaScript object, so they follow JavaScript and DOM property naming rather than HTML attribute naming. And because JSX is parsed strictly like XML, the forgiving rules browsers apply to HTML (unclosed tags, bare attributes) do not apply.
The differences you will hit
| HTML | JSX | Why |
|---|---|---|
class="card" |
className="card" |
class is a reserved word in JavaScript |
for="email" |
htmlFor="email" |
for is a reserved word |
<br>, <img …>, <input …> |
<br />, <img … />, <input … /> |
Every element must be closed |
style="margin-top: 8px" |
style={{ marginTop: "8px" }} |
Styles are an object with camelCase keys |
tabindex="0" |
tabIndex="0" |
DOM property names are camelCase |
onclick="save()" |
onClick={save} |
Events take functions, not strings |
<!-- note --> |
{/* note */} |
HTML comments are not valid in JSX |
stroke-width="2" (SVG) |
strokeWidth="2" |
SVG attributes are camelCased too |
{ in text |
{"{"} |
Curly braces start JavaScript expressions |
A few attributes keep their hyphens: data-* and aria-* attributes are written exactly as in HTML, and CSS custom properties in a style object stay quoted, as in style={{ "--accent": "#4f46e5" }}.
Multiple root elements
A component must return one root element. If your HTML has two siblings at the top level, wrap them in a fragment: <>…</>.
Inline styles as objects
The style conversion is mechanical but easy to get wrong by hand. -webkit-border-radius: 12px becomes WebkitBorderRadius: "12px". Unitless numbers are allowed for many properties, so padding: 24px can become padding: 24 in React, although keeping the string is always safe.
Forms: value versus defaultValue
In HTML, value on an input is just the starting value. In React, value makes the input controlled: React sets the value on every render, so without an onChange handler that updates state, the user cannot type in it. React warns you about this.
When converting static HTML, you usually want the input to behave as it did before, which means uncontrolled:
<input type="email" id="email" defaultValue="" required />
<input type="checkbox" defaultChecked />
<textarea rows={3} defaultValue="Hello team" />
Later, if you need React to track the value, switch to value plus onChange and state. Note also that <textarea> takes its content as a value or defaultValue prop rather than as child text.
Event handlers
Inline HTML handlers like onclick="track('signup')" are strings of code. In JSX they must be functions:
<button type="submit" onClick={() => track("signup")}>Subscribe</button>
A converter can wrap the original code in an arrow function so the component compiles, but the functions it calls, such as track or handleSubmit, still need to exist in your component or be imported. Also check for event references: in React, the handler receives a synthetic event as its argument, and global event is not reliable.
Convert HTML with the HTML to JSX Converter
Our HTML to JSX Converter handles the mechanical rules above in your browser.
- Open the HTML to JSX Converter. A sample signup card with inline styles, a form, an image, an SVG and inline event handlers is loaded.
- Paste your markup into HTML, or click Open file to load an
.html,.htmor.svgfile. - Set the options:
- Wrap in a component outputs
export default function MyComponent() { return (…); }. Set a Component name starting with a capital letter. - Uncontrolled inputs converts
valuetodefaultValueandcheckedtodefaultCheckedon form fields. - Indentation is 2 or 4 spaces.
- Wrap in a component outputs
- Read the JSX output.
classbecomesclassName,forbecomeshtmlFor, styles become objects, void elements are self-closed, attributes and events are camelCased, HTML comments become JSX comments, and several top-level elements are wrapped in a fragment. - Click Copy or Download to save it as a
.jsxfile.
Other ways to convert
By hand, with a checklist
For a few lines of markup, editing by hand with the table above is fine. For a full page template, it is slow and easy to miss a class or unclosed tag somewhere.
Editor extensions and linters
Several editor extensions paste HTML as JSX. Once converted, ESLint with React rules and TypeScript catch remaining problems such as unknown props.
Rethinking the structure
A converter gives you one large component. The real work is splitting it into smaller components, replacing repeated markup with .map() over data, and moving inline styles into your styling system. Tidy the source first with the HTML Formatter so the structure is easier to see, and format the result with the JavaScript Formatter. You can test behaviour of the original markup in the HTML CSS JS Editor before converting.
Pitfalls after converting
Scripts inside the markup
<script> tags in JSX do not run like they do in HTML. Move the logic into the component, usually in an effect, or load external scripts through your framework's mechanism. A converter may keep them with dangerouslySetInnerHTML so nothing is silently lost, but treat that as a to-do note, not a finished solution.
Relative image paths
src="/logo.svg" depends on your project's public folder setup. Check paths, or import images if your bundler supports it.
Duplicate IDs
Components are reused. An id="email" that was unique on a page becomes a duplicate when a component renders twice. Consider React's useId for label associations.
Frequently asked questions
Why does React use className instead of class?
JSX compiles to JavaScript, where class is a reserved keyword. React uses the DOM property name className instead.
How do I write inline styles in JSX?
Pass an object to style with camelCase property names, for example style={{ backgroundColor: "#fff", marginTop: 8 }}.
Why can I not type in an input after converting to JSX?
It has a value prop, which makes it controlled, but no onChange handler. Use defaultValue for uncontrolled inputs, or add state and an onChange handler.
Does the converter handle SVG?
Yes. SVG attributes such as stroke-width and fill-rule are converted to their camelCase JSX names, like strokeWidth and fillRule.
Will the converted component work straight away?
The JSX will be syntactically valid, but functions referenced in event handlers, image paths and any scripts still need attention in your project.