Skip to content

HTML to JSX Converter

HTML to JSX Converter

JSX looks like HTML, but it isn't. React reuses JavaScript's variable-naming rules, which means 'class' becomes 'className', 'for' becomes 'htmlFor', and event handlers like 'onclick' become 'onClick'. Inline styles that were strings become JavaScript objects with camelCase property names. Void elements must self-close. This tool handles all of that in one paste-and-copy operation.

What Gets Converted

Attribute renames — class → className, for → htmlFor, tabindex → tabIndex, readonly → readOnly, maxlength → maxLength, and 30+ other renames. Event handlers — onclick → onClick, onchange → onChange. Only the first letter after "on" is capitalised, so multi-word events (onMouseOver, onKeyDown) and string handler values need fixing by hand. Void element self-closing — <img>, <input>, <br>, <hr> get proper <img /> syntax. Style strings to objects — 'color: red; font-size: 16px' becomes {{color: 'red', fontSize: '16px'}}. HTML comments — converted to JSX-compatible {/* */} syntax. Boolean attributes — checked, disabled, required become explicit true assignments (the same words in your text are changed too; see the worked example).

📖
Deep Dive: The Complete HTML to JSX Guide
The full attribute rename list, inline-style object conversion, boolean attributes, edge cases with SVG and scripts, and what the converter leaves for you to wire up.
→

Common Use Cases

Porting a static landing page into a React component without manually fixing class vs className, for vs htmlFor, self-closing void elements, and inline-style strings on every element. Bringing a Figma-export or Webflow-export HTML snippet into a Next.js or Remix app. Cleaning up AI-generated HTML before pasting it into a JSX file so the build doesn't reject it for missing closes or stray boolean attributes.

Quickly checking what a chunk of marked-up content looks like in JSX form before committing to refactoring it into proper components — the conversion makes the syntactic friction visible at a glance. Every inline style attribute string becomes a JSX object literal, every tabindex becomes tabIndex, and every boolean attribute gets the right JSX shape, which helps scope the eventual cleanup.

Worked example: nine conversions rendered by React

The converter now works on the document your browser parses, not on the raw text, so a word in a sentence can never be mistaken for an attribute. On October 13, 2026 we converted nine awkward snippets in Chromium 141, compiled each result with Babel 7.26 and rendered it with React 18.3.1's renderToStaticMarkup, then compared the rendered DOM (tags, attributes, styles, text) with the original HTML: identical 9 of 9, with no React warnings.

CaseBefore (v215)Now
Prose: "the default class for the label is open"words rewritten: class=…, open={true} inside the sentencetext untouched: only attributes are converted
Text with {name}copied as is: a JSX expression, so the component threw "name is not defined"{'{'}name{'}'}: renders the braces
onmouseover, ondblclickonMouseover, onDblclick: not React events, ignoredonMouseOver, onDoubleClick from React's event list
onclick="submit()"string handler: React rejects it and warnsan arrow function holding the code in a comment, plus a warning to move it
SVG stroke-width, fill-rule, xlink:hrefleft as written: React warns and drops somestrokeWidth, fillRule, xlinkHref
Text split across lines, e.g. "Click / <a> / to"JSX trims the line breaks: "Clickhereto"{' '} kept where the browser would show a space
input value, checkedvalue without onChange (read-only warning)defaultValue, defaultChecked

Sources

Checked on .

Frequently Asked Questions

Why can't I just paste HTML into a React component?+
JSX looks like HTML but isn't. 'class' is reserved in JavaScript, so React uses 'className'. Event handlers use camelCase (onClick, not onclick). Inline styles are JS objects, not strings. Void elements must self-close.
Does this handle inline styles?+
Yes. A style string like 'color: red; font-size: 16px' becomes a JSX object: {{color: 'red', fontSize: '16px'}}. CSS property names are converted to camelCase and values are wrapped in strings.
What about HTML comments?+
They become JSX comments, {/* like this */}, in the same place. Inline <script> blocks are turned into comments too, because React does not run them.
Will it wrap the output in a component?+
Optionally, yes. Toggle 'Wrap as component' to get a complete functional component with export default. Otherwise you get the raw JSX fragment.
What does the converter actually change?+
Only markup, never your text. It parses the HTML the way a browser does, then writes JSX: class and for become className and htmlFor, other attributes get React's names (tabIndex, SVG strokeWidth, xlinkHref), style strings become objects, void elements self-close, braces and angle brackets in text are escaped, spaces JSX would drop are kept with {' '}, input value and checked become defaultValue and defaultChecked, and comments become {/* */}.
Does it handle SVG correctly?+
Yes. SVG attributes keep their case (viewBox) and hyphenated or namespaced ones are converted to React's names: stroke-width to strokeWidth, fill-rule to fillRule, xlink:href to xlinkHref. In our React render test the SVG case came out identical to the original.
Can I generate functional component scaffolding?+
Toggle the component option and the output is wrapped in an export default function component (plain JSX, no TypeScript types) that returns the converted markup inside a fragment.
What about inline event handlers like onclick="alert(1)"?+
They become React event props with the right names (onClick, onMouseOver, onDoubleClick), but React takes functions, not strings, so the code is placed in a comment inside an empty arrow function and listed under the output for you to move: onClick={() => { /* alert(1) */ }}.

Built by Derek Giordano · Part of Ultimate Design Tools

Privacy Policy · Terms of Service