Skip to content
ToolPlankDEV
Developer Tools
100% In-Browser Execution

Updated:

HTML to JSX Converter

Paste HTML and get JSX that React accepts. This html to jsx converter renames attributes, turns style strings into objects, closes void tags, fixes SVG names and lists every change it made. Nothing is uploaded.

Options:

Choose a component output to name it

HTML

Input
0 chars · 0 lines

JSX

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

What changed

Renamed attributes, event handlers and notes appear here.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use HTML to JSX

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste your HTML

    Paste a snippet or a whole page into the left box, or open an .html file. Example loads a small signup card with a style attribute, a comment, an inline SVG and an onclick.

  2. 02

    Choose the output

    Keep just the JSX, or wrap it in a function or arrow function component with a name you choose. Pick 2 or 4 spaces for the indent.

  3. 03

    Decide about event attributes

    An attribute such as onclick holds a string in HTML, while React needs a function. Remove them and see them listed, or wrap each one in a function you then review.

  4. 04

    Check what changed and copy

    The panel under the result lists every renamed attribute, each event handler and any note. Press Copy to put the JSX on your clipboard.

How to convert HTML to JSX

JSX looks like HTML, but it is JavaScript, so a copy and paste from an HTML file fails in a few predictable places. To convert html to jsx, the tool reads your HTML, renames the attributes React expects, turns style strings into objects, closes the tags HTML leaves open and checks the result is valid JSX.

The built-in example, a signup card, converts to this. The status line reports 8 attributes renamed and 1 style converted:

jsx
<>
  {/* Signup card */}
  <div className="card" style={{ padding: "16px", backgroundColor: "white", opacity: 0.9 }}>
    <h2 className="card__title" tabIndex={0}>Join us</h2>
    <p>Read the <a href="/terms" target="_blank">terms</a> first.</p>
    <label htmlFor="email">Email</label>
    <input id="email" type="email" maxLength={80} required />
    <input type="checkbox" defaultChecked /> Remember me
    <br />
    <svg viewBox="0 0 24 24" strokeWidth="2">
      <path d="M5 12h14" strokeLinecap="round" />
    </svg>
  </div>
</>

What changes when you convert HTML to JSX

  • Attribute names. class becomes className and for becomes htmlFor. Names such as tabindex, colspan, maxlength, readonly and autofocus take their camelCase form.
  • Style attributes. A string like padding: 16px; background-color: white becomes an object with camelCase keys. Unitless numbers such as opacity become real numbers.
  • Void tags. <br>, <img>, <input> and <hr> get a closing slash.
  • Comments. An HTML comment becomes a JSX comment in braces.
  • Form fields. value on a text input becomes defaultValue, and checked becomes defaultChecked, so React does not treat the field as controlled. A selected option moves to defaultValue on its select, and the text of a textarea moves to its defaultValue.
  • Tables. Rows placed straight inside a table are wrapped in a tbody, as a browser would, because React warns about them otherwise.
  • Special characters. Braces and angle brackets in text are written as string expressions, since they have a meaning in JSX.

HTML to JSX for SVG

Inline SVG has its own attribute names, written with hyphens in HTML and in camelCase in JSX: stroke-width becomes strokeWidth, stroke-linecap becomes strokeLinecap, and xlink:href becomes xlinkHref. Names that are already camelCase in SVG, such as viewBox, are kept. If you only have an SVG file, SVG to JSX is built for it and also offers component and TypeScript output.

Event attributes: onclick and friends

In HTML, onclick="save()" is a string of code. In React, onClick takes a function, so the string cannot be passed along. By default the tool removes these attributes and lists them so you know where to add handlers. Choose Wrap in a function and each one becomes onClick={() => { save() }}. That is a starting point only, because code written for HTML often relies on globals, this or the old event object.

Script tags are kept as written but React does not run them. Move that code into handlers or effects.

HTML to JSX component output

Pick Function component for export default function Name() { return (...); }, or Arrow function component for a const Name = () => (...) followed by a default export. The name is turned into a valid PascalCase identifier. If your HTML has more than one top-level element, the result is wrapped in a fragment, <>...</>, because a component must return one root.

To go back, use JSX to HTML, which turns className, style objects and other JSX details into plain HTML. To clean up HTML before converting, HTML Encoder and HTML Decoder handle entities, and Remove HTML Tags strips markup you only need as text.

Line breaks and spacing

JSX ignores a line break together with the spaces around it. The converter follows that rule: text and inline tags that sit on one line in your HTML stay on one line in the JSX, with their spaces. A line break between two tags is treated as formatting and is not kept as a space. Preformatted text in pre keeps every space and line break, written as a template string.

Limits

  • The tool checks syntax, not behavior. Open the JSX in your project to catch props React rejects.
  • Whole pages lose their html, body and head tags, and so do the title, meta and link tags, since a component cannot contain them.
  • Attributes written with unusual capitals are matched in lowercase, except inside SVG.
  • Inline event code is not translated to React code.

Your HTML is converted in your browser. It is not uploaded or stored. See the Privacy Policy for details.

Frequently Asked Questions

Technical Q&A for HTML to JSX

Common questions about edge cases, character encoding, and privacy guarantees.

Paste your HTML into the left box. The JSX appears on the right at once, with class renamed to className, style strings turned into objects and void tags closed. Press Copy to use it.

In JSX, class is a reserved word in JavaScript, so the attribute is called className. The converter renames it for you, and it does the same for for, which becomes htmlFor.

A style string becomes an object with camelCase keys, for example background-color becomes backgroundColor. Values stay as text, apart from unitless numbers like opacity, which become numbers.

Yes. Choose Function component or Arrow function component and enter a name. The JSX is placed inside a component that returns it.

They are removed and listed by default, because React needs a function and not a string. You can also choose Wrap in a function to get a starting point for each handler.

Yes. Hyphenated attributes such as stroke-width become strokeWidth, and xlink:href becomes xlinkHref. For a whole .svg file, SVG to JSX has more options.

The JSX it produces is valid in a .tsx file as well, since TSX is JSX with types. Add prop types to the component yourself.

Browsers insert a tbody around table rows automatically, and React warns when it is missing. The converter adds it for you.

Yes. The html, head and body tags are removed and the content of the body is converted. Title, meta and link tags are dropped too.

No. The conversion runs in your browser and nothing is sent to a server.