HTML to JSX Converter
Turn HTML into JSX: class becomes className, style strings become objects, void tags are closed, comments are converted and SVG attributes are renamed.
How to convert HTML to JSX
Paste your HTML
Paste or type it into the box, or press Try an example.
Choose the wrapper
Output a full component or just the markup.
Copy or download
Paste it into your React project.
Worked example
This is what HTML to JSX Converter gives for its own sample values. Open the tool above and change anything to try your own.
HTML
<div class="card" style="padding: 8px; background-color: #fff"> <!-- title --> <label for="n">Name</label> <input type="text" id="n" tabindex="1" disabled> <img src="a.png" alt="A"> <svg viewBox="0 0 10 10"><path stroke-width="2" d="M0 0L10 10"/></svg> <button onclick="save()">Save</button> </div>
- Wrap in a React component
- Yes
- Component name
- Component
JSX
export default function Component() {
return (
<div className="card" style={{ padding: "8px", backgroundColor: "#fff" }}>
{/* title */}
<label htmlFor="n">Name</label>
<input type="text" id="n" tabIndex={1} disabled />
<img src="a.png" alt="A" />
<svg viewBox="0 0 10 10"><path strokeWidth="2" d="M0 0L10 10" /></svg>
<button onClick={() => { save() }}>Save</button>
</div>
);
}
About HTML to JSX Converter
Turn HTML into JSX for React: class becomes className, for becomes htmlFor, style strings become objects, void tags are closed, comments become {/* */} and SVG attributes such as stroke-width become strokeWidth.
FAQs
Does it handle inline scripts and events?
Event attributes become arrow functions you can fill in. Inline <script> tags need to be moved into your code.
What about several root elements?
They are wrapped in a fragment.
Does it work for SVG?
Yes. Paste the SVG markup.