About the HTML to JSX converter
JSX looks like HTML, but React has its own rules. Attributes such as class and for become className and htmlFor, inline styles must be JavaScript objects, and every tag has to be closed. Pasting HTML from a template, a design tool or an old project straight into a component usually breaks the build.
This converter reads your HTML with the browser's own parser and rewrites it as valid JSX. It can return the JSX on its own or wrap it in a ready-to-use React function component.
How to use the HTML to JSX converter
- Paste your HTML into the Input editor, or click Load sample.
- Choose JSX only or React component in the Output menu.
- Click Convert to JSX or press Ctrl + Enter (Cmd + Enter on Mac).
- Read any notes in the status bar, then click Copy result.
Example
Convert a form snippet
Input
<label for="email" class="field">Email</label>
<input type="email" id="email" autofocus>
<div style="margin-top: 8px; font-size: 14px">We never share it.</div>Output
<>
<label htmlFor="email" className="field">Email</label>
<input type="email" id="email" autoFocus />
<div style={{ marginTop: "8px", fontSize: "14px" }}>We never share it.</div>
</>class becomes className, for becomes htmlFor, void tags self-close and the style string becomes an object.
Common errors and how to fix them
Warning: Invalid DOM property `class`. Did you mean `className`?
HTML attributes were pasted into JSX unchanged. Convert the markup so class becomes className and for becomes htmlFor.
The `style` prop expects a mapping from style properties to values, not a string.
JSX needs style={{ marginTop: "8px" }}, not style="margin-top: 8px". Converting the HTML rewrites style strings into objects.
Adjacent JSX elements must be wrapped in an enclosing tag.
A component can only return one root element. Wrap the elements in <>...</> (a fragment) or a <div>.
Good to know
- Renames attributes such as
class,for,tabindexandcolspanto their React names;data-*andaria-*attributes stay unchanged. - Turns
style="font-size: 12px"intostyle={{ fontSize: "12px" }}, closes void tags like<br />and<img />, and camel-cases SVG attributes likestroke-width. - Form values become
defaultValueanddefaultChecked, so the fields stay editable without React warnings. - Inline event handlers such as
onclick="..."are removed and listed in the status bar, because React needs functions, not strings. - Several top-level elements are wrapped in a fragment,
<>...</>, because a component must return a single root.
Frequently asked questions
Why does React use className instead of class?
JSX compiles to JavaScript, where class is a reserved word. React uses the DOM property names instead, so class becomes className and for becomes htmlFor.
Does it work with TypeScript (TSX)?
Yes. The output is plain JSX, which is also valid TSX. Paste it into a .tsx file and add types to any props you introduce.
What happens to <script> tags and comments?
HTML comments become JSX comments like {/* comment */}. Script contents are kept as text, but inline scripts don't run when React renders them, so move that logic into your component.