HTML to JSX Converter

Convert raw HTML code to valid React JSX. Handles className, camelCase attributes, self-closing tags, inline style objects, and all JSX syntax differences. Free browser tool.

How to use HTML to JSX Converter

  1. 1

    Paste your HTML code into the input area.

  2. 2

    The converter automatically transforms all HTML attributes to JSX equivalents.

  3. 3

    Review the output: class→className, for→htmlFor, style strings→objects, self-closing tags.

  4. 4

    Copy the converted JSX code to use in your React component.

Frequently Asked Questions

What is the difference between HTML and JSX?

JSX is a JavaScript syntax extension used in React. Key differences: class becomes className, for becomes htmlFor, all void elements must self-close (e.g., <br/>), and inline styles use JavaScript objects.

Does this handle inline styles?

Yes. style="font-size: 14px; color: red" is converted to style={{fontSize: "14px", color: "red"}} with camelCased property names.

What attributes are not automatically converted?

SVG-specific attributes, custom data-* attributes (which remain unchanged), and application-specific attributes that fall outside the HTML spec.

Detailed Guide

Why HTML and JSX Are Different

When you start building with React, one of the first friction points is that JSX looks like HTML but isn't. Copy-paste a block of HTML from a design tool, a template, or a CMS preview, and React will throw errors. The syntax differences are small but mandatory.

Our HTML to JSX converter handles all the transformations automatically, so you can paste any HTML and get valid React code in seconds.


Key Differences: HTML vs JSX

classclassName class is a reserved word in JavaScript. JSX uses className for CSS classes.

<!-- HTML -->
<div class="container main">

<!-- JSX -->
<div className="container main">

forhtmlFor Same reason — for is a JavaScript reserved keyword (for loops).

<label for="email">   →   <label htmlFor="email">

Self-closing tags are mandatory In HTML, <br>, <input>, <img> don't need closing. In JSX, every tag must be closed.

<input type="text">   →   <input type="text" />
<br>                  →   <br />

Inline styles become JavaScript objects HTML inline styles are strings. JSX expects a JavaScript object with camelCased property names.

<!-- HTML -->
<div style="font-size: 14px; background-color: red;">

<!-- JSX -->
<div style={{ fontSize: '14px', backgroundColor: 'red' }}>

Event handlers use camelCase

onclick="handler()"   →   onClick={handler}
onchange="handler()"  →   onChange={handler}

tabindextabIndex All HTML attributes that are two words are camelCased in JSX: tabIndex, readOnly, autoFocus, maxLength, colSpan, rowSpan, etc.

<!-- comments -->{/* comments */} HTML comments become JSX expression comments.


What Our Converter Handles

classclassName (all occurrences)
forhtmlFor
✅ Self-closing all void elements (br, hr, img, input, link, meta, area, base, col, embed, param, source, track, wbr)
✅ Inline style string → JavaScript style object with camelCased properties
✅ HTML comments → JSX expression comments
✅ Event handler attribute names to camelCase
✅ Boolean attributes (disabled, checked, readonlyreadOnly)
tabindextabIndex, colspancolSpan, etc.


Limitations

A few HTML patterns require manual attention after conversion:

  • SVG attributes use camelCase in JSX (strokeWidth, fillOpacity) — our tool handles most common ones
  • **data-* and ...

Looking for a more detailed deep-dive and advanced tips?

Read Full Article on our Blog