Code & Media

HTML to JSX

Convert HTML to JSX or TSX, handling attributes, styles, and comments.

  • Draft kept in this tabYour draft is kept in this tab's session storage and cleared when the tab closes.
  • Runs in your browserProcessing happens in this page. No application server receives your input.
Load sample

HTML fragment input

Generated JSX output

Conversion summary

Renamed attributes
0
Dropped active items
0
Mode
JSX
Execution
In-page

What this tool does

Converts an HTML fragment into JSX or TSX entirely locally, renaming reserved HTML and SVG attributes, closing void elements, converting inline style strings into JSX style objects, rewriting HTML comments, and stripping active content without rendering or executing markup.

Conversion rules

  • Reserved HTML and SVG attributes (such as class, for, tabindex, readonly, maxlength, stroke-width, fill-rule, and xlink:href) are renamed to their React camelCase equivalents and counted in Renamed attributes.
  • HTML void elements (such as <br>, <hr>, <img>, and <input>) are emitted as self-closing JSX tags (<br />).
  • Inline style strings (such as style="color:red; margin-top: 4px") are parsed into JSX style objects (style={{ color: 'red', marginTop: '4px' }}), preserving CSS custom properties (--var) as quoted keys.
  • Active content (<script>, <style>, on* event-handler attributes, srcdoc, and javascript:/vbscript:/data:text/html URLs) is dropped and counted in Dropped active items (FR-CODE-1).
  • HTML comments (<!-- ... -->) become JSX expression comments ({/* ... */}), boolean attributes without a value become bare JSX attributes, and custom elements (hyphenated tag names) keep their tag and attribute names unchanged.
  • When an optional component name is provided, the JSX fragment is wrapped in an exported function component (with a : JSX.Element return annotation in TSX mode).
  • Empty or whitespace-only input is the neutral cleared state and produces empty output with no error (GAP-013).

Operational limits & execution

Maximum input size: 512.0 KB (returns InputTooLarge above cap). Maximum element nesting depth: 128 levels (returns DepthExceeded). Unclosed or mismatched tags return MalformedMarkup naming the UTF-8 byte offset. Execution runs in-page below 256.0 KB and offloads to codegen.worker.ts at or above 256.0 KB with cooperative cancellation.

Worked example

Input:

<div class="card" style="color:red"><br></div>

Expected output:

<div className="card" style={{ color: 'red' }}>
  <br />
</div>

Scope: this covers the page itself. Your browser, operating system, clipboard, downloads, extensions, and crash recovery may keep copies, and a compromised site origin would not be protected.