Skip to content
My Tiny Utils

Search tools

Type to find a tool, then press Enter to open it.

HTML to JSX Converter

Convert HTML to valid React JSX — className, htmlFor, style objects, self-closing tags, SVG attributes, and event handlers — optionally wrapped in a component.

Processed locally in your browser — nothing is uploaded.

HTML to JSX Converter

0 characters

JSX

Output appears here…

About the HTML to JSX Converter

Paste HTML — a snippet from a design system, a Bootstrap or Tailwind example, an exported SVG icon, a whole landing page — and get JSX you can drop into a React, Next.js, or Preact component. Turn on Wrap in a component to get a complete export default function with the name you choose.

Everything that makes pasted HTML fail in React is handled:

  • Attribute names: class becomes className, for becomes htmlFor, and tabindex, maxlength, colspan, readonly, autofocus, http-equiv and the rest get React's camelCase. data-* and aria-* stay as they are.
  • Inline styles become style objects: style="font-size: 12px; z-index: 2" becomes style={{ fontSize: "12px", zIndex: 2 }}, with vendor prefixes (WebkitTransition) and custom properties ("--gap") written the way React expects.
  • Void elements like <br>, <img>, and <input> are self-closed, and so are empty elements.
  • SVG keeps working: viewBox, linearGradient, and clipPath get their camelCase back, and stroke-width, fill-rule, and xlink:href become strokeWidth, fillRule, and xlinkHref.
  • Event handlers written as strings (onclick="save()") become functions (onClick={() => save()}), and the converter reminds you to check them.
  • Comments become {/* … */}, and text JSX would misread — braces, <, > — is escaped.
  • Form fields use defaultValue and defaultChecked, and <option selected> becomes the <select>'s defaultValue, so React doesn't warn about a value without an onChange.
  • Whitespace is laid out so the JSX renders the same spaces as the HTML. JSX drops whitespace that contains a line break, so where a space between words and links would fall at a line break, it's written as {" "}.

The output is checked against TypeScript's own parser in this tool's tests, so it works in .tsx files as well as .jsx. HTML that isn't perfectly formed — an unclosed <p> or <li> — is parsed the way a browser would and comes out properly nested.

Example

Input

<label for="email" class="label">Email</label>
<input type="email" id="email" style="width: 100%" required>

Output

<>
  <label htmlFor="email" className="label">Email</label>{" "}
  <input type="email" id="email" style={{ width: "100%" }} required />
</>

Common uses

  • Move a static HTML page or template into a React or Next.js app
  • Use a component example from Bootstrap, a UI kit, or a design system's docs in JSX
  • Paste an SVG icon exported from Figma or Illustrator as a React component
  • Fix "Invalid DOM property class" and "Unterminated JSX contents" errors in pasted markup

Limitations

  • Converted event handlers are a starting point: in React, this isn't the element, and handlers usually belong in the component as functions
  • <script> tags are converted but React doesn't run scripts it renders — load them in an effect or with your framework's script component
  • Framework attributes that aren't valid JSX names, like Alpine's @click or Vue's :class, are passed through a spread rather than translated

Frequently asked questions

How do I convert HTML to JSX?

Paste the HTML into the left box and the JSX appears on the right as you type. Attributes are renamed (class to className, for to htmlFor), inline styles become style objects, void tags are self-closed, and comments become JSX comments. Copy the result, or turn on “Wrap in a component” to get a complete React component.

Why does React use className instead of class?

JSX compiles to JavaScript, where class is a reserved word, and React's props follow the DOM property names — element.className and label.htmlFor — rather than the HTML attribute names. The converter renames them, along with the other attributes React spells in camelCase.

How do I convert an inline style string to a React style object?

Paste the element and the converter does it: each CSS declaration becomes a camelCase key with a string value, like style={{ backgroundColor: "#fff", marginTop: "8px" }}. Unitless numbers React understands, such as zIndex or opacity, are written as numbers, and custom properties keep their names as quoted keys.

Can I convert an SVG to JSX?

Yes. SVG attributes like stroke-width, fill-rule, and xlink:href become strokeWidth, fillRule, and xlinkHref, and camelCase names such as viewBox and linearGradient are kept. Turn on “Wrap in a component” to get an icon component you can import.

Is my HTML uploaded anywhere?

No. The HTML is parsed as text and converted in your browser — it's never rendered, so scripts in it can't run, and nothing you paste leaves your device.