Skip to content

HTML to JSX

✨ Converts as you type 0 lines · 0 B

JSX

Paste HTML on the left

React-ready JSX will appear here
Nothing to convert yet

HTML to JSX Converter – Free Online Tool

What is JSX, and Why Doesn’t HTML Just Work in React?

JSX is the HTML-like code you write inside React components. It looks almost like HTML, but it’s really JavaScript, and that’s why pasting a chunk of HTML into a component usually ends in a wall of errors. class is a JavaScript word, so React calls it className. style="color: red" has to be an object, style={{ color: 'red' }}. <br> must be closed as <br />, and a { in your text starts a piece of JavaScript.

This converter does those fixes for you. Paste a snippet from a template, a design tool or an old site, and you get JSX you can drop into a component, plus a short list of the things only you can finish (like what a button should do when it’s clicked). It runs in your browser, so nothing you paste is uploaded.

How to Use It – Step by Step

Five short steps. Paste the examples into the tool above to try them.

Step 1 Paste or Open Your HTML

  • Paste it: a snippet, a component from a UI kit, or a whole page.
  • Open a file: click the upload button, or drag an .html or .svg file onto the tool.
  • Click Sample: loads a sign-up card with an image, a form, a button with an onclick, inline styles and an SVG icon.

The JSX on the right updates a moment after you stop typing.

Try it: a label and an input

HTML:

<label for="email" class="field-label">Email</label>
<input type="email" id="email" class="field" tabindex="1">

JSX:

<>
  <label htmlFor="email" className="field-label">Email</label>{' '}
  <input type="email" id="email" className="field" tabIndex={1} />
</>

💡 Two elements side by side need one parent, so they’re wrapped in a fragment <>...</>. The {' '} keeps the space between the label and the input (more on that in the FAQ).

Step 2 Pick Your Options

The strip above the result lets you shape the code. Your choices are remembered in this browser.

  • Indent: 2 or 4 spaces.
  • Form fields: defaultValue (the field starts with the HTML’s value and people can still type) or value (you’ll control it with state).
  • Component: wraps the JSX in export default function Name() { return (...); }. Type any name; it’s turned into PascalCase, so “pricing card” becomes PricingCard.
  • Comments: keep <!-- comments --> as {/* comments */}, or drop them.
  • Self-close empty tags: <div /> instead of <div></div>.
  • Body only: shows up for a whole page and converts only what’s inside <body>.

Try it: tick Component and type “note”

HTML:

<p class="note">Hi there</p>

JSX:

export default function Note() {
  return (
    <p className="note">Hi there</p>
  );
}

Step 3 Read the Notes Tab

Notes, next to Code, lists what was changed for you (Done) and what you still need to look at (To do): event handlers to fill in, scripts that were left out, !important values that a style object can’t hold. The number on the tab is the count of to-dos, or of notes when there’s nothing to do.

Step 4 Fill In the Event Handlers

Every onclick, onchange or onsubmit becomes an empty function with the old code in a comment. Swap the comment for the real call once that function exists in your component.

Try it: a button with an onclick

HTML:

<button onclick="save()">Save</button>

JSX from the tool, then filled in by you:

<button onClick={() => { /* was: save() */ }}>Save</button>

<button onClick={() => save()}>Save</button>

Step 5 Copy or Download

  • Copy: puts the JSX on your clipboard.
  • Download: saves a .jsx file, named after your component (or the page title).
  • Messy HTML? Unclosed or badly nested tags make messy JSX. Tidy the HTML first with the HTML Formatter or check it with the HTML Validator.
  • Want to see the HTML first? Try it live in the HTML Editor, then bring it here.

HTML vs JSX: the Differences That Matter

These are the changes the converter makes. They’re worth knowing, because you’ll type them by hand too.

1. Some Attributes Have Different Names

React uses the JavaScript property names: camelCase, and className / htmlFor because class and for are taken. aria-* and data-* stay exactly as they are. Props React types as numbers (tabIndex, maxLength, colSpan) are written as {1}, so they also pass in TypeScript.

HTMLJSX
class className
for htmlFor
tabindex tabIndex
readonly readOnly
maxlength maxLength
colspan / rowspan colSpan / rowSpan
autocomplete autoComplete
autofocus autoFocus
enctype encType
srcset srcSet
crossorigin crossOrigin
http-equiv httpEquiv
onclick, onchange, onsubmit onClick, onChange, onSubmit
stroke-width, fill-rule (SVG) strokeWidth, fillRule
xlink:href (SVG) xlinkHref
aria-label, data-id aria-label, data-id (unchanged)

2. style Is an Object

Property names turn into camelCase and values go in quotes. Plain numbers stay numbers only where CSS needs no unit (zIndex, opacity, lineHeight, flex, fontWeight) and for 0, so React never adds a px the HTML didn’t have. CSS variables keep their name as a quoted key.

Try it: an inline style

HTML:

<div style="background-color: #f3f4f6; margin-top: 8px; z-index: 10; --gap: 4px">Box</div>

JSX:

<div
  style={{
    backgroundColor: '#f3f4f6',
    marginTop: '8px',
    zIndex: 10,
    '--gap': '4px',
  }}
>
  Box
</div>

3. Every Tag Is Closed

HTML lets <br>, <img>, <input> and <hr> stand alone. JSX doesn’t, so they get a slash: <br />.

HTML:

<p>Line one<br>Line two</p>
<img src="cat.jpg" alt="A cat">
<hr>

JSX:

<>
  <p>Line one<br />Line two</p>
  <img src="cat.jpg" alt="A cat" />
  <hr />
</>

4. One Root, or a Fragment

A component returns one thing. Two elements next to each other get wrapped in a fragment, <>...</>, which groups them without adding a <div> to the page.

HTML:

<h1>Title</h1>
<p>Some text</p>

JSX:

<>
  <h1>Title</h1>
  <p>Some text</p>
</>

5. Curly Braces in Text

In JSX, { starts a JavaScript expression. To show a brace as text, it’s written as {'{'}. The same goes for < and > in text, which become &lt; and &gt;. Other characters (é, ©, emoji) come through as they are, and a non-breaking space stays &nbsp; so you can still see it.

HTML:

<p>Write {name} to show a variable.</p>

JSX:

<p>Write {'{'}name{'}'} to show a variable.</p>

6. Form Fields Start With defaultValue

An input with value is locked in React until you add an onChange. The HTML only meant “start with this”, so the converter writes defaultValue and defaultChecked. A <textarea>’s text and an <option selected> become a defaultValue too.

HTML:

<input type="text" value="Ann">
<input type="checkbox" checked>

JSX:

<>
  <input type="text" defaultValue="Ann" />{' '}
  <input type="checkbox" defaultChecked />
</>

What It Can’t Do

Frequently Asked Questions

Why can’t I paste HTML straight into a React component?

JSX looks like HTML but it’s JavaScript underneath, so a few things break. class and for are JavaScript words, so React uses className and htmlFor. style needs an object, not a string. Every tag has to be closed, so <br> becomes <br />. Event attributes need a function, not a string of code. And curly braces in text start a JavaScript expression. This tool fixes all of that for you.

What happens to onclick and other event attributes?

They get React’s name (onclick becomes onClick, ondblclick becomes onDoubleClick) and an empty arrow function, with the old code in a comment inside it: onClick={() => { /* was: save() */ }}. React can’t run a string of code, and the old code often calls functions that won’t exist in your component, so you fill in the body yourself. The Notes tab lists every one.

How are inline styles converted?

style="margin-top: 4px; z-index: 10" becomes style={{ marginTop: '4px', zIndex: 10 }}. Property names turn into camelCase, -webkit- prefixes become Webkit, and CSS variables like --gap stay as quoted keys. Values stay strings, except plain numbers on properties that need no unit (opacity, zIndex, lineHeight, flex, fontWeight) and 0. That way React never adds a px the HTML didn’t have. !important is dropped, because style objects can’t set it.

Why did value become defaultValue?

In React, an input with value is “controlled”: it only changes when your code changes it, so without an onChange people can’t type in it. defaultValue (and defaultChecked for checkboxes) just sets the starting value, which is what the HTML meant. If you plan to keep the value in state, pick “value” under Form fields. <option selected> becomes defaultValue on the <select>, and the text inside a <textarea> becomes its defaultValue.

What does {' '} mean in the output?

It’s a space. JSX throws away whitespace that contains a line break, so when a line of JSX ends right where the HTML had a space (between a label and an input, say), the converter adds {' '} to keep it. Without it, “Read our” and the link next to it would run together.

What happens to <script> and <style> tags?

<script> tags are left out and listed in the Notes tab. React doesn’t run scripts written inside the markup, so that code belongs in your component (often in a useEffect) or in a separate file. <style> tags are kept, with the CSS inside a template string: <style>{`...`}</style>. That works, though a CSS file or CSS module is usually tidier.

Can I convert a whole HTML page?

Yes. When the HTML has a doctype, <html>, <head> or <body>, the Body only option shows up and is on by default, so you get just what’s inside <body>, which is what a component normally returns. Untick it to convert the whole page, <html> and <head> included, for example for a root layout.

Does the output work in TypeScript (.tsx) files?

Mostly, yes. Number props like tabIndex, maxLength and colSpan are written as numbers ({1}, not "1"), so they match React’s types. The main thing TypeScript complains about is CSS variables in a style object: add as React.CSSProperties after the object, like style={{ '--gap': '4px' } as React.CSSProperties}.

Is my HTML sent anywhere?

No. The conversion runs in your browser, and nothing you paste is uploaded or saved. Your option choices (indent, component name and so on) are remembered in this browser only.