About HTML to JSX Converter
Paste markup from a design, a template or an old page and get JSX you can drop into a React component. class becomes className, for becomes htmlFor, attributes such as tabindex and stroke-width are camel-cased, inline styles become style objects, and void tags like <br> and <img> are closed.
Text that JSX would misread, such as braces and angle brackets, is escaped; comments become JSX comments; and several top-level elements are wrapped in a fragment. You can also have the result wrapped in a named function component. Inline event handlers like onclick="…" are removed and listed, because JSX needs a function there.
How it works
- The HTML is read the way a forgiving browser reads it: unclosed paragraphs and list items are closed where the next one starts, and a stray closing tag is ignored.
- Each attribute is given its React name. Known HTML names use React’s spelling (tabIndex, readOnly, colSpan), hyphenated and namespaced ones are camel-cased (strokeWidth, xlinkHref), and data- and aria- attributes are kept as written.
- Whitespace is kept where a browser would show it, beside inline elements such as links and bold text, and dropped between blocks, where it is only indentation. The contents of <pre> are kept exactly.
- With the default option, value and checked on inputs become defaultValue and defaultChecked, so the field stays editable without state.
Questions
Why were my onclick attributes removed?
In HTML an event attribute holds code as a string; in JSX it must be a function such as onClick={handleClick}. Converting the string would mean guessing what it refers to, so the tool removes it and tells you which handlers to rewrite.
Does it work for SVG?
Yes. SVG keeps its case-sensitive names such as viewBox, and attributes like stroke-width, fill-rule and xlink:href become strokeWidth, fillRule and xlinkHref, which is what React expects.
Is the output valid for TypeScript too?
Yes. The markup is the same in .jsx and .tsx files. Style values are written as strings, which TypeScript accepts for every CSS property.
How much HTML can it convert?
Up to 1 MB, nested up to 500 elements deep. Conversion happens in your browser as you type, and nothing is uploaded.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.