HTML to JSX Converter - Paste HTML, Get React Code

Convert HTML to valid JSX instantly: class becomes className, inline styles become objects, void tags self-close, and comments become JSX comments. Free and fully in-browser.

What gets converted

  • class to className, for to htmlFor, tabindex to tabIndex
  • All standard attributes to camelCase (maxlength to maxLength, colspan to colSpan, onclick to onClick)
  • style="..." strings to style={{...}} objects with camelCased properties
  • Void elements (br, img, input, hr, meta) self-closed
  • HTML comments to {/* ... */} JSX comments
  • data-* and aria-* attributes preserved unchanged

HTML to JSX Converter for React Developers

Convert any block of HTML into JSX that compiles cleanly in a React project. The converter parses your markup with a real HTML parser rather than fragile find-and-replace rules, then rebuilds it as JSX: reserved words like class and for become className and htmlFor, attributes are renamed to their camelCase React equivalents, void elements are self-closed, and inline style strings become proper JavaScript style objects.

React developers use this constantly when migrating legacy pages, porting Bootstrap or Tailwind templates, converting email markup, or lifting snippets from documentation and CodePen examples into components. Designers handing off HTML prototypes and students learning React also benefit, because the tool shows exactly how HTML syntax maps onto JSX conventions.

JSX is not HTML: it compiles to JavaScript function calls, so attribute names must be valid JavaScript identifiers. That is why class (a JS keyword) becomes className and tabindex becomes tabIndex. Inline styles change shape entirely, from a CSS string to an object where background-color becomes backgroundColor. Unclosed tags like br and img are legal in HTML but syntax errors in JSX, which requires every element to be closed. This tool handles all of those rules, including vendor prefixes in styles and SVG attributes such as viewBox and stroke-width.

The embedded attribute map covers more than 100 attribute renames, and data-* plus aria-* attributes pass through untouched exactly as React expects. Curly braces in text nodes are escaped so pasted template syntax cannot break your component, and HTML comments are preserved as JSX comments instead of being silently dropped.

Everything runs locally in your browser, so proprietary markup never leaves your machine. Pair it with our JSON Formatter when preparing component props, or the Markdown to HTML converter when your source content starts as Markdown rather than HTML.

How the HTML to JSX Converter Works

  1. 01Paste your HTML into the left pane, or load the sample to see the conversion rules in action.
  2. 02The markup is parsed with the browser's real HTML parser (DOMParser), not regex substitution.
  3. 03Each element is rebuilt as JSX: attributes renamed, styles converted to objects, void tags self-closed, comments wrapped.
  4. 04Copy the JSX from the right pane straight into your React component.

Converting HTML Snippets Into React Components

Paste any fragment: a full page body, a single card, or an SVG icon. Because the converter uses DOMParser, it tolerates the messy HTML you find in the wild - unquoted attributes, unclosed tags, and inconsistent casing all normalize correctly before conversion. The output follows React's rules exactly: class becomes className, for becomes htmlFor, tabindex becomes tabIndex, and the rest of the attribute map covers form attributes (maxlength, readonly, autocomplete), table attributes (colspan, cellpadding), media attributes (autoplay, playsinline), event handlers (onclick to onClick), and SVG names such as viewBox and preserveAspectRatio. Inline style strings turn into style objects with camelCased properties, including vendor prefixes (-webkit-transform becomes WebkitTransform) and CSS custom properties, which stay quoted. Multiple top-level elements are wrapped in a fragment so the result is always a valid return value. After pasting into your component, replace static attribute values with props or state where needed, and convert onClick string handlers into real function references - the converter preserves them as attribute text since it cannot invent your handler logic.

When to Use the HTML to JSX Converter

Use it whenever HTML needs to live inside a React component: porting a static site or landing page to Next.js, adapting a Bootstrap or Tailwind template, embedding an SVG exported from Figma or Illustrator, or copying a snippet from documentation that was written for plain HTML. It is also a teaching aid - the side-by-side view makes JSX's differences from HTML concrete for developers learning React.

Common Use Cases

  • Porting static HTML pages or templates into React and Next.js components
  • Converting SVG icons exported from design tools into inline JSX
  • Adapting HTML email markup or CMS output for a React front end
  • Learning how JSX differs from HTML with instant side-by-side feedback
  • Cleaning up markup before formatting props as JSON JSON Formatter & Validator - Instant Results
  • Converting Markdown-sourced HTML into components Markdown to HTML Converter - Live Preview

Expert Tips

  • After converting, extract repeated blocks into components and replace hardcoded text with props - the converter gives you valid JSX, but componentization is still your job.
  • For big SVGs, consider running the output through an optimizer first; fewer path nodes means less JSX to maintain.
  • Boolean attributes like disabled and checked convert to bare props; remember that in React, checked needs an onChange handler or defaultChecked instead.

Frequently Asked Questions

Why does class become className?
JSX compiles to JavaScript, where class is a reserved keyword. React therefore uses className for the class attribute, and htmlFor for the label attribute for. The converter applies these and over 100 other renames automatically.
How are inline styles handled?
A style string like style="background-color: red; margin-top: 8px" becomes a JavaScript object: style={{ backgroundColor: "red", marginTop: "8px" }}. Vendor-prefixed properties and CSS custom properties are converted correctly too.
Are data- and aria- attributes changed?
No. React expects data-* and aria-* attributes in their original hyphenated form, so the converter passes them through unchanged.
What happens to HTML comments?
They are preserved as JSX comment expressions ({/* ... */}) instead of being dropped, so documentation embedded in the markup survives the conversion.

Related tools

12 suggested