HTML to JSX
Convert HTML to JSX for React online: class becomes className, inline styles become objects, SVG attributes are camelCased and void tags self-close.
Runs in your browser · Nothing uploaded · No sign-up
Something not working, or missing a feature? Send feedback
About the HTML to JSX
The HTML to JSX Converter rewrites HTML so you can paste it into a React component: class becomes className, for becomes htmlFor, inline styles become style objects and SVG attributes such as stroke-width are camelCased. Void tags self-close, tags HTML closes implicitly are closed, and your formatting is kept.
Conversion happens in your browser, so your files and records stay private.
How to use the HTML to JSX
- Paste HTML or SVG markup.
- Choose JSX, or Component to wrap it in a function component, and name the component.
- Copy the JSX into your React or Next.js code.
HTML attributes that change in JSX
| HTML | JSX |
|---|---|
| class | className |
| for | htmlFor |
| tabindex | tabIndex |
| style="margin-top: 4px" | style={{ marginTop: '4px' }} |
| onclick | onClick |
| stroke-width | strokeWidth |
| xlink:href | xlinkHref |
| value (input) | defaultValue |
| <br> | <br /> |
Sources: React: common components (props)
Examples
Input
<label class="field" for="email">Email <input id="email" type="email" required=""></label>
Result
<label className="field" htmlFor="email">Email <input id="email" type="email" required /></label>
required="" would be false in React, so it becomes a bare prop.
Input
<svg viewBox="0 0 24 24" fill="none" stroke-width="2"><path stroke-linecap="round" d="M5 12h14"/></svg>
Result
<svg viewBox="0 0 24 24" fill="none" strokeWidth="2"><path strokeLinecap="round" d="M5 12h14" /></svg>
Input
<div style="margin-top: 8px; background-color: #f5f5f5">Hi {name}</div>Result
<div style={{ marginTop: '8px', backgroundColor: '#f5f5f5' }}>Hi {'{'}name{'}'}</div>Input
<h1>Hello</h1> <p>Welcome back.</p>
Result
export default function Hero() {
return (
<>
<h1>Hello</h1>
<p>Welcome back.</p>
</>
);
}Common mistakes
- Text with braces. JSX reads { and } as code. They are escaped as {'{'}, so template placeholders such as {name} need to be turned into real expressions by hand.
- Several root elements. A component returns one element, so several top-level tags are wrapped in a fragment (<>…</>).
Works well with the HTML to JSX
- HTML Formatter: tidy the HTML before converting.
- JavaScript Formatter: format the JSX with Prettier.
- HTML Viewer: preview the original HTML.
Frequently asked questions
What does the converter change?
Attribute names (class, for, tabindex, colspan and others), inline styles, SVG and xlink attributes, boolean attributes, comments ({/* */}) and void tags such as <br> and <img>, which must be self-closed in JSX.
What happens to onclick and other inline handlers?
They become React props with an arrow function, for example onClick={() => { save() }}. Code that uses this or event inside should be rewritten to use the event argument.
Why does value become defaultValue?
In React, value on an input makes it controlled, which needs an onChange handler. defaultValue and defaultChecked set the starting value like HTML does.
Does it work with TypeScript (TSX)?
Yes. The output is plain JSX, which is also valid TSX.
Related tools
JSON to CSV
Convert JSON arrays to CSV online with automatic column detection, nested object flattening and custom delimiters. Open the result in Excel or Sheets.
CSV to JSON
Convert CSV to a JSON array online with header detection, type inference and delimiter auto-detection. Turn spreadsheet exports into data for APIs and code.
JSON to XML
Convert JSON to well-formed XML online with a configurable root element and attribute support. Validate the input and download the XML file.
XML to JSON
Convert XML to JSON online, keeping attributes and turning repeated elements into arrays. Malformed XML is reported with its location.
JSON to YAML
Convert JSON to clean, human-readable YAML online. Turn API responses and package files into config for Kubernetes, Docker Compose or CI pipelines.
YAML to JSON
Convert YAML documents to formatted JSON online with syntax validation. Errors are reported by line, so broken indentation is quick to find and fix.