HTML to JSX

Convert HTML markup into valid JSX (class->className, style objects, self-closing).

The HTML to JSX converter rewrites plain HTML markup so it can be pasted into a React component. It renames attributes such as class and for, turns inline style strings into style objects, and closes void tags. It is meant for developers moving static templates, snippets from documentation or exported markup into React code.

What is JSX and why does HTML need converting?

JSX is the XML-like syntax React uses to describe UI inside JavaScript. It looks like HTML but follows JavaScript rules. Attribute names use the DOM property names, so class becomes className, for becomes htmlFor and tabindex becomes tabIndex. The style attribute is not a string but an object with camelCase keys, such as style={{ fontSize: '12px' }}. Every element must be closed, so void elements like input, img and br are written with a trailing slash. Event handlers are camelCase functions rather than strings, and curly braces in text are special because they open a JavaScript expression. Converting by hand is tedious and easy to get subtly wrong, so a converter that applies these rules consistently saves time. The result still needs a quick review before you ship it.

How to use HTML to JSX

  1. Paste your HTML Put the markup in the HTML box. A sample is shown as a placeholder if the box is empty.
  2. Choose the wrapper Leave Wrap in a component unticked for bare JSX, or tick it to wrap the result in export default function Component().
  3. Read the JSX Convert to JSX is the selected operation, so the JSX box fills in as you type and updates when you change the checkbox.
  4. Copy or download Copy the output or save it as component.jsx, then review it in your editor.

Frequently asked questions

Does it convert every HTML attribute?

It maps the common ones (class, for, tabindex, readonly, maxlength, colspan, charset, srcset and many others) to their React names and keeps data-* and aria-* attributes as they are. Unusual attributes are passed through, so scan the output for anything React warns about.

What happens to style and script tags?

The content of a style or script element is emitted as a template literal inside curly braces so that JSX can parse it. The tags themselves are kept.

Why is the output not formatted like Prettier?

The tool indents with two spaces and keeps one element per line, but it does not wrap long attribute lists. Run your formatter afterwards.

Does it handle text with special characters?

Ampersands and angle brackets in text are escaped as entities, and literal { and } are written as {'{'} and {'}'} so JSX does not treat them as expressions.

Is my markup sent anywhere?

No. The conversion runs in the page and the input stays on your device.