HTML to JSX Converter

JSX output will appear here

Paste HTML on the left or load a sample

READY
LN 1, COL 10 CHARS

About the HTML to JSX Converter

The HTML to JSX Converter turns HTML and inline SVG into JSX you can paste into a React component. It renames attributes (`class` to `className`, `for` to `htmlFor`, `tabindex` to `tabIndex`), turns `style` strings into style objects, camelCases SVG attributes such as `stroke-width` and `viewBox`, self-closes void elements, and escapes text that JSX would misread. The markup is parsed by your browser's own `DOMParser` into an inert document: no script in it runs, no image or stylesheet in it is fetched, and nothing is sent to our servers or analytics. Your options are saved in the page address; the HTML is not, and it goes into a link only when you click Share.

Updated: November 13, 2026

How to use the converter

  • Paste HTML or an SVG file into the input, or drop a `.html`, `.htm`, `.svg`, or `.txt` file on it. The JSX on the right updates as you type.
  • Choose JSX for a bare snippet, or Component to wrap it in `export default function Component() { return (...); }`. The component name must start with an uppercase letter and use only letters, digits, `_`, or `$`; while it is invalid, `Component` is used.
  • Pick 2-space or 4-space indentation, and switch the defaultValue and Comments options on or off (both are on by default).
  • Copy the result, or click Save to download it as `Component.jsx` or `.tsx`, named after your component.

What gets converted

  • Attributes. `class`, `for`, and multi-word attributes get their React names: `readonly` becomes `readOnly`, `maxlength` becomes `maxLength`, `colspan` becomes `colSpan`, `http-equiv` becomes `httpEquiv`, `charset` becomes `charSet`, `enctype` becomes `encType`, and so on. `aria-*` and `data-*` attributes are kept as they are. Attribute names JSX cannot express, such as Vue or Alpine `@click` and `:class`, are kept in a spread: `{...{ '@click': "open = true" }}`.
  • Boolean attributes. `disabled`, `checked`, `required`, `readonly`, `multiple`, `hidden`, and the other HTML boolean attributes are written bare (`<input disabled />`) when their value is empty or repeats the name.
  • Form values. With defaultValue on, `value` on `input`, `select`, and `textarea` becomes `defaultValue` and `checked` on `input` becomes `defaultChecked`, so the fields stay editable without an `onChange` handler. Textarea content moves into that attribute. Turn the option off to keep `value` and `checked` for a controlled component.
  • Styles. `style="font-size: 12px; -webkit-transition: none; --accent: red"` becomes `style={{ fontSize: '12px', WebkitTransition: 'none', '--accent': 'red' }}`. Every value stays a string, `-ms-` prefixes become `ms`, custom properties keep their quoted name, and semicolons and colons inside `url(...)` or quotes (such as a `data:image/png;base64,...` URL) do not split a declaration.
  • SVG. Element names keep their case (`linearGradient`, `foreignObject`), and hyphenated or namespaced attributes are camelCased: `stroke-width` to `strokeWidth`, `fill-rule` to `fillRule`, `xlink:href` to `xlinkHref`, `xml:space` to `xmlSpace`. An `<?xml ...?>` declaration and doctype at the top of an SVG file are dropped.
  • Structure. Void elements are self-closed (`<br />`, `<img />`, `<input />`), as are elements with no children. Several top-level nodes are wrapped in a Fragment, `<>...</>`. A full document converts from `<html>` down.

Text, whitespace, comments, and scripts

  • Text. `{` and `}` are written as `{'{'}` and `{'}'}`, and `<`, `>`, and `&` as `&lt;`, `&gt;`, and `&amp;`, which JSX decodes like HTML. A non-breaking space is written as `&nbsp;`; other entities such as `&copy;` are written as the character itself.
  • Whitespace. Runs of spaces and line breaks collapse to one space. Whitespace that is only a line break between tags is dropped, as JSX would drop it; a space between inline elements on the same line is kept as `{' '}`. Inside `<pre>`, text is written as a template literal so spaces and line breaks survive exactly.
  • Comments. HTML comments become `{/* ... */}`; turn Comments off to drop them.
  • Inline event handlers. `onclick="track('signup')"` becomes `onClick={() => { /* track('signup') */ }}`: the prop gets its React name, and the original code is kept as a comment inside an empty function. React props take functions, not code strings, so you port the logic by hand.
  • Script and style elements. `<script>` elements are removed and replaced with a `{/* <script> removed */}` comment (with the `src` if it had one); load scripts with `useEffect` or your framework's script component instead. `<style>` elements are kept, with the CSS in a template literal: `<style>{`...`}</style>`.

Privacy

Parsing uses `DOMParser`, which builds a detached document that never touches the page you are viewing, so scripts in the markup do not run and its images, iframes, and stylesheets are not loaded. Conversion happens in your browser tab and the markup is not sent to our servers or analytics. Your options (output mode, component name, indent, toggles, and file type) are saved in the page address; the HTML is not. It goes into a link only when you click Share, compressed with lz-string, which is not encryption, so anyone with the link can read it. Remove private URLs and tokens before sharing.

Frequently Asked Questions

What happens to onclick and other inline event handlers?
They become React event props with an empty arrow function, and the original code is kept as a comment inside it: `onclick="save()"` becomes `onClick={() => { /* save() */ }}`. `ondblclick` maps to `onDoubleClick`. The code is not copied in as a function body because an inline handler is a string the browser evaluates with the element, its form, and the document in scope; that code usually needs rewriting for a component anyway.
Why does value become defaultValue?
In React, `value` or `checked` without an `onChange` handler makes a read-only field and logs a warning. `defaultValue` and `defaultChecked` set the starting value and leave the field editable, which matches how the HTML behaved. Turn the defaultValue option off if you plan to make the field controlled.
Can I convert an SVG file into a React component?
Yes. Paste or drop the `.svg` file, choose Component, and set a name such as `Logo`. The XML declaration and doctype are dropped, attributes like `stroke-width`, `fill-rule`, and `xlink:href` become `strokeWidth`, `fillRule`, and `xlinkHref`, and `class` becomes `className`.
Are HTML entities kept?
The markup is decoded first, then written back for JSX. `&lt;`, `&gt;`, `&amp;`, and `&nbsp;` are written as those entities, which JSX supports in text. Other entities such as `&copy;` or `&mdash;` become the character itself.
Why are some spaces written as {' '}?
JSX removes whitespace at the start and end of each line. When a space sits between two inline elements or between text and an element, the converter writes it as `{' '}` so the rendered output keeps the gap, as the HTML did.
Is my HTML uploaded anywhere?
No. Parsing and conversion run in your browser with the built-in `DOMParser`, in a detached document where scripts do not run and resources are not loaded. The HTML is not saved in the page address; it is included in a link only when you click Share.