Tools / HTML to JSX Converter

HTML to JSX Converter.

Convert HTML into valid React JSX - className, htmlFor, style objects, self-closing tags and safe text.

Runs in your browser

Wraps the JSX in an exported function component. Leave empty for plain JSX.

Ctrl/⌘ + Enter to run · Ctrl/⌘ + Shift + C to copy the result

Result

About HTML to JSX Converter

The HTML to JSX Converter rewrites HTML so it compiles as React JSX. It renames attributes that differ in React - class becomes className, for becomes htmlFor, tabindex becomes tabIndex, readonly becomes readOnly and dozens more - and turns inline event handlers such as onclick into onClick functions. Inline styles become style objects with camelCased properties, vendor prefixes like -webkit-transition become WebkitTransition and CSS custom properties keep their quoted names. Void elements such as <input> and <br> are closed as <input />, comments become {/* … */}, and characters JSX treats specially in text, the curly braces and angle brackets, are escaped so they render literally. Form fields get defaultValue and defaultChecked instead of value and checked, and a selected <option> moves to defaultValue on its <select>, which is what React expects for uncontrolled inputs. Whitespace that matters between inline elements is kept as {' '}, <pre> and <textarea> content keeps its exact spacing, and inline SVG keeps its case-sensitive attributes such as viewBox. Several top-level elements are wrapped in a fragment. Give a component name to get a ready-to-use exported function component. For example <label for="email" class="lbl"> becomes <label htmlFor="email" className="lbl">. Typical leftovers to review are inline handlers that reference this or global functions. The conversion runs in your browser.

How to Use

  1. Paste HTML into the input.
  2. Optionally enter a component name and choose comment and indent options.
  3. Copy the JSX into your React component.

Frequently Asked Questions

Why does value become defaultValue?

In React, value without an onChange handler makes a read-only controlled input. defaultValue sets the initial value of an uncontrolled input, which matches how the HTML behaved.

What happens to inline event handlers?

onclick="doThing()" becomes onClick={(event) => { doThing(); }}. Check them afterwards, because global functions or this may not exist in your component.

Does it handle inline SVG?

Yes. Inside <svg> hyphenated attributes such as stroke-width become strokeWidth, and case-sensitive names like viewBox are kept. Use the SVG to JSX tool for standalone icon files.

Is my HTML sent anywhere?

No. The conversion runs in your browser.

Related Tools