Home / Converters

HTML to JSX Converter

Runs locally in your browser. Your input is not uploaded.

HTML and JSX look similar, but JSX uses JavaScript-oriented property names, expressions for style objects, explicit closing syntax, and special handling for text characters such as braces. This converter applies those mechanical changes to an HTML fragment or full document and produces editable React-oriented markup.

Conversion is a starting point, not a guarantee that the result has the right component boundaries or behavior. The browser first parses the source as HTML, which can repair malformed markup and normalize names. Review the output in the context of your React application, especially events, form state, scripts, and custom components.

How to Use the HTML to JSX Converter

Edit the included example or replace it with your own markup.

  1. Paste or type markup into HTML.
  2. Leave Wrap in a component selected to generate an exported function, or clear it to output JSX only.
  3. When wrapping is selected, edit Component name to choose the generated function name.
  4. Review the converted result in JSX and read the status for conversion warnings.
  5. Select Copy to copy the current JSX output.

HTML Attributes, React Props, and Inline Styles

JSX uses className instead of class and htmlFor instead of for. The converter also maps common attributes such as tabindex, readonly, maxlength, autocomplete, autofocus, srcset, and allowfullscreen to their React prop casing. Hyphenated SVG attributes are camel-cased, while data-* and aria-* names remain unchanged.

Form defaults receive special treatment. An input, textarea, or select value becomes defaultValue; an input checked becomes defaultChecked; and textarea text becomes a defaultValue prop. An <option selected> attribute is removed with a warning because React expects selection to be expressed through defaultValue on the parent select.

Inline CSS is converted from a string to a JSX style object:

<button style="background-color: #123; padding: 8px">Save</button>
<button style={{ backgroundColor: "#123", padding: "8px" }}>Save</button>

CSS custom properties keep their quoted names. Unitless numeric-looking values other than 0 become JavaScript numbers; other values remain strings. The parser simply splits declarations on semicolons and the first colon, so complex or malformed style text should be checked manually. It does not determine whether a particular React style property expects a number or a unit.

Elements, Fragments, Comments, and Text Handling

HTML void elements such as input, img, br, and meta become self-closing JSX. Elements with no parsed children also become self-closing. When the source has multiple top-level nodes, the converter wraps them in a shorthand fragment so the result can occupy one JSX expression.

HTML comments become JSX comments. Literal {, }, <, and > characters in text are escaped as JSX expressions so React does not interpret them as syntax. Text-node whitespace is collapsed and trimmed, which creates tidy output but can change intentional spacing in prose, preformatted content, or inline-element boundaries.

The converter parses a source containing an <html> start tag as a full document. Other input is parsed inside a template element as a fragment. In both cases, the browser's DOMParser applies HTML parsing rules before conversion, so omitted end tags, invalid nesting, entity references, and attribute normalization may not remain byte-for-byte equivalent to the source.

Tag names come from the parsed DOM rather than a JSX compiler. Standard HTML and SVG markup are the intended input. If your source already contains JSX components, expressions, spread props, or template syntax, the HTML parser can reinterpret or discard that syntax; do not use this tool as a JSX-to-JSX formatter.

Event Handlers, Scripts, and React Behavior

An HTML event attribute such as onclick="save()" cannot safely become a React callback by changing its capitalization. The converter therefore keeps inline event attributes as JSX comments and displays a warning to rewrite them as functions. You must connect the result to handlers defined in your component.

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

Replace the comment with an expression such as onClick={save} only after the function and its intended behavior are clear. The converter does not generate imports, hooks, state, refs, or controlled-form logic. Defaults such as defaultValue and defaultChecked create uncontrolled initial values; applications that manage those fields in state will need value, checked, and change handlers instead.

If the input contains a <script> element, the status warns that script content was copied as text and should move to effects or imports. Merely placing a script-shaped element in JSX does not reproduce the lifecycle or security model of an HTML page. External dependencies, document-level metadata, and imperative initialization need deliberate React integration.

Component Names, Validation, and Safe Conversion

With Wrap in a component selected, the output is an export default function returning the converted JSX. The name field defaults to MyComponent. The generator removes characters other than word characters and $, capitalizes an initial lowercase ASCII letter, and falls back to MyComponent when the field is empty.

That cleanup is limited and does not fully validate JavaScript identifiers or avoid reserved words. A name beginning with a digit, for example, can still produce invalid code. Run the result through your project's parser, type checker, linter, or build after choosing a valid component name.

Conversion runs locally in the browser, and the HTML is not uploaded by this tool. Even so, avoid sharing output that contains private form defaults, internal URLs, tokens, or personal data. HTML from an untrusted source can also contain deceptive links or active-content instructions; conversion changes syntax but does not sanitize intent.

For readable source before conversion, the HTML beautifier can help expose structure. If you need to see what ordinary HTML renders, use HTML Preview, keeping in mind that rendering and converting answer different questions.

Frequently Asked Questions

What does this converter change from HTML to JSX?

It maps common HTML attributes to React prop names, converts inline styles to object syntax, self-closes empty and void elements, turns comments into JSX comments, and escapes JSX-sensitive text. It also adjusts common form defaults and adds a fragment for multiple roots. The browser parser may normalize the HTML before those changes are applied.

Why are inline event handlers turned into comments?

HTML event attributes contain strings, whereas React event props expect JavaScript functions. Automatically treating an arbitrary string as executable code would produce misleading or unsafe output. Rewrite each commented handler as a function reference or callback that fits your component's state and dependencies.

Does the generated JSX compile without changes?

It may for straightforward HTML, but the tool does not run a JSX compiler or validate the final JavaScript. Component names, complex styles, browser-repaired markup, scripts, and application-specific components can require edits. Check the result with the same compiler and lint rules used by your project.

Why did whitespace or nesting change?

The input is parsed with the browser's HTML parser, which repairs certain malformed structures and builds a DOM. The converter then collapses and trims whitespace in text nodes while formatting the tree. Review content where exact spacing matters, including pre, inline prose, and text surrounding nested elements.

Can I use this to convert a complete website into React?

No. It converts markup syntax and can wrap the result in one function component, but it does not design a component hierarchy, migrate CSS, recreate scripts, add routing, fetch data, or model state. Use it for a bounded fragment, then refactor the output around the application's behavior and ownership boundaries.

References: React: Writing Markup with JSX · MDN: DOMParser.