HTML to JSX

Paste HTML or SVG, get JSX, and see what to double-check.

Runs in your browser Instant No sign-up
Output
HTML
JSX

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How to use the HTML to JSX converter

  1. Paste HTML or SVG: a snippet, a component from a template, or an icon exported from a design tool. The JSX appears as you type.
  2. Output chooses plain JSX markup, or a React component that wraps it in export default function Component().
  3. Read the notes under the result. They list what may not behave the same in React, and they are the part worth your attention.
  4. More options: keep or drop the {' '} between inline elements, and indent with 2 spaces, 4 spaces or a tab.
  5. Copy the JSX or Download it as Component.jsx.

Example

The sample card:

<!-- Contact card -->
<div class="card" style="max-width: 320px; border: 1px solid #ddd">
  <div>
    <label for="email">Email</label>
    <input id="email" type="email" value="ann@example.com" tabindex="1">
  </div>
  <button class="btn" onclick="send()">Send</button>
  <svg viewBox="0 0 24 24" width="16" height="16" xmlns="http://www.w3.org/2000/svg">
    <path d="M4 12l5 5L20 6" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round"/>
  </svg>
</div>

becomes:

<>
  {/* Contact card */}
  <div className="card" style={{ maxWidth: '320px', border: '1px solid #ddd' }}>
    <div>
      <label htmlFor="email">Email</label>
      {' '}
      <input id="email" type="email" defaultValue="ann@example.com" tabIndex="1" />
    </div>
    <button className="btn" onClick={() => { send() }}>Send</button>
    {' '}
    <svg viewBox="0 0 24 24" width="16" height="16" xmlns="http://www.w3.org/2000/svg">
      <path d="M4 12l5 5L20 6" stroke="currentColor" strokeWidth="2" fill="none" strokeLinecap="round" />
    </svg>
  </div>
</>

The comment, the root fragment (JSX needs a single root, and the comment counts as one), className, htmlFor, tabIndex, the style object, the self-closed input and path, strokeWidth and strokeLinecap are all rewritten. Two notes appear: the input’s value became defaultValue, and the inline onclick was wrapped in a function.

What changes

  • class becomes className and for becomes htmlFor; tabindex, colspan, maxlength, readonly, autocomplete, http-equiv and the other attributes React spells differently follow.
  • A style="a: b" string becomes an object with camelCase keys (font-size to fontSize), vendor prefixes (-webkit-box-shadow to WebkitBoxShadow) and custom properties kept as '--gap'. Semicolons inside url(data:…;base64,…) do not split a declaration.
  • SVG attributes are renamed (stroke-width to strokeWidth, xlink:href to xlinkHref, xmlns:xlink to xmlnsXlink) and tags such as lineargradient get their case back (linearGradient).
  • Void elements (br, img, input, hr) and anything written with /> are self-closed. Optional end tags are closed for you, so <li>a<li>b becomes two closed items.
  • Comments become {/* … */}. In text, { and } are escaped as {'{'} and {'}'}, and <, > and & as entities, because JSX cannot hold them raw.
  • Tags React treats as components are left as written, and known HTML tags are written in lowercase.

What needs a second look

The notes under the result name each of these:

  • Inline handlers (onclick="send()") become onClick={() => { send() }}. The code is copied as it is, so this is no longer the element and the implicit event variable is gone. Rewrite it as a real handler that takes the event as a parameter.
  • checked and value on inputs become defaultChecked and defaultValue (see the FAQ). Inputs of type checkbox, radio, submit, button, reset and hidden keep value.
  • <script> is kept with dangerouslySetInnerHTML, and React does not run it when it renders on the client. Load scripts another way.
  • <table> with <tr> and no <tbody>: browsers insert the tbody, React warns about the missing one.
  • !important in a style is removed, because React inline styles ignore it.
  • Namespaced elements and attributes from editors are removed, and attributes that belong to other frameworks (@click, :class) are removed because JSX cannot spell them.

Whitespace, pre and textarea

JSX trims whitespace at line breaks, HTML collapses it, and the two rules differ. Text that mixes with elements stays on one line so it reads the same. The content of pre is written as a template literal, so line breaks and indentation survive, and the one newline a browser drops after <pre> is dropped too. The text of a textarea moves into defaultValue.

What it does not do

It converts markup, not behaviour: it does not split the result into components, turn a class list into Tailwind or CSS modules, or translate inline JavaScript. For tidier source first, run it through the HTML Formatter; to shrink SVG before converting use the SVG Optimizer. To turn HTML into Markdown instead of JSX, see HTML to Markdown, and for the reverse problem of shipping less markup, the HTML Minifier.

Frequently asked questions

Does it run my HTML or send it anywhere?

No. A small parser reads the markup in your browser and writes text; nothing in the HTML is executed, rendered or uploaded. A script tag stays a block of text in the result.

Why does {' '} appear between some elements?

In HTML, whitespace between two inline elements such as a label and an input, or two buttons, is shown as a space. JSX drops whitespace that contains a line break, so the converter writes {' '} to keep that space and the page looking the same. Switch off Keep spaces between inline elements (More options) for shorter code, and check the spacing in the browser afterwards.

Why did checked and value become defaultChecked and defaultValue?

In React an input with value or checked is controlled: it needs state and an onChange handler or it cannot be edited. defaultValue and defaultChecked set only the starting state, which is what a static HTML form means. If your state should drive the field, change them back and add onChange.

Can I paste a whole page, with doctype, head and body?

Yes, but only the content of body is converted, because JSX has no form for the doctype, html or head (title, meta and link belong to your router or framework). A note says so when it happens.

What about SVG exported from Figma, Illustrator or Inkscape?

Attributes such as stroke-width, fill-rule, viewBox and xlink:href are renamed, and lowercased SVG tags and attributes get their camelCase back. Editor metadata in other namespaces (inkscape:label, sodipodi:namedview, rdf:RDF) cannot be written in React JSX, so it is removed and listed in the notes. Run the file through the SVG Optimizer first for the smallest result.

Why are attributes like hx-get and x-data left as they are?

React keeps custom hyphenated attributes (data-*, aria-*, htmx and Alpine attributes) exactly as written. Only the SVG attributes that React spells in camelCase, such as stroke-width, are renamed.

Last updated