How do I convert HTML to JSX for React?
Paste your HTML and instantly get valid JSX with 50+ attribute conversions — class to className, for to htmlFor, inline styles to objects, SVG attributes to camelCase, and void elements self-closed. The tool shows a change log of all transformations. Everything runs in your browser.
<div class="container"> <label for="email">Email</label> <input type="email" tabindex="1" /> </div>
<div className="container"> <label htmlFor="email">Email</label> <input type="email" tabIndex="1" /> </div>
HTML to JSX Converter
Convert HTML to valid JSX — transforms attributes, inline styles, comments, void elements, event handlers, and SVG attributes.
Examples
HTML Input
JSX Output
<div className="container"> <h1 className="title">Hello World</h1> <p className="text-gray-500">Welcome to my app.</p> </div>
Changes Made
class→className×3HTML → JSX Quick Reference
| HTML | JSX | Why |
|---|---|---|
| class="..." | className="..." | "class" is a reserved word in JavaScript |
| for="..." | htmlFor="..." | "for" is a reserved word in JavaScript |
| style="color: red" | style={{ color: 'red' }} | JSX styles are objects, not strings |
| <!-- comment --> | {/* comment */} | JSX uses JS comment syntax |
| <br> | <br /> | JSX requires self-closing void tags |
| <img ...> | <img ... /> | All void elements must self-close |
| tabindex="0" | tabIndex="0" | JSX uses camelCase attributes |
| onclick="..." | onClick={() => {}} | Event handlers are camelCase functions |
| colspan="2" | colSpan="2" | Multi-word attributes are camelCase |
| stroke-width="2" | strokeWidth="2" | SVG attributes use camelCase in JSX |
Tips & Best Practices
class → className is just the start
Beyond class → className, HTML-to-JSX conversion handles 50+ attribute renames: for → htmlFor, tabindex → tabIndex, onclick → onClick, stroke-width → strokeWidth, and all SVG attributes. Missing even one causes React warnings and broken functionality.
Inline style strings must become objects
HTML: style="margin-top: 10px; background-color: red". JSX: style={{ marginTop: '10px', backgroundColor: 'red' }}. The conversion involves camelCasing every CSS property and wrapping values as strings. Numeric values (except unitless ones like zIndex) need string quotes.
Port HTML email templates to React Email or MJML
Email templates are notoriously HTML-heavy with inline styles and legacy attributes. Converting to JSX is the first step toward using React Email, which lets you build email templates with components. Convert the HTML, then extract repeated patterns into reusable React components.
innerHTML → dangerouslySetInnerHTML is intentionally scary
React renamed innerHTML to dangerouslySetInnerHTML as a warning. If your HTML uses innerHTML, the converter preserves it — but you should replace it with proper React components. Rendering user-supplied HTML via dangerouslySetInnerHTML is the #1 source of XSS in React apps.
Frequently Asked Questions
How do I convert HTML to JSX for React?
What are the key differences between HTML and JSX syntax?
Does the converter handle inline styles and SVG attributes?
Related Convert Tools
URL Encoder & Decoder
Encode and decode URLs with encodeURIComponent and encodeURI
JSON ↔ YAML Converter
Convert between JSON and YAML for Kubernetes, Docker, and CI/CD configs
HTML Entity Encoder
Encode and decode HTML entities, special characters, and symbols
Image to Base64
Convert images to Base64 data URIs or decode Base64 back to images