HTML to JSX Converter

Runs 100% in your browser

Convert HTML to JSX online with React property mappings, inline style objects, defaultValue, TypeScript support, fragment wrapping, event handlers, boolean props, entities, and download — all private, no upload.

HTML INPUT

Source markup

0 bytes
0 lines
JSX OUTPUT

React-ready markup

Waiting
0 bytes 0 lines
CONVERSION REVIEW

Mapping notes & warnings

0 mappings
Load or paste HTML to see JSX mappings, warnings, and statistics.
STATISTICS

Conversion metrics

No upload
Input bytes
JSX bytes
Elements
Mappings
Warnings
Fragments
Recent conversions (this session)
No conversions yet.
Conversion ? compilation. The output is JSX-ready source. It does not run Babel, compile TypeScript, execute event handlers, sanitize untrusted HTML, or guarantee that framework templates will render unchanged. Always run through your project's compiler and lint pipeline before use.
?? All processing runs locally in your browser using DOMParser. No HTML is uploaded to any server, stored in localStorage, or retained after you close the tab.

Frequently asked questions

An HTML to JSX converter transforms plain HTML markup into valid JSX syntax for React components. It renames reserved attributes (class → className, for → htmlFor), converts inline style strings into JavaScript objects, maps HTML events to camelCase React handler props, wraps boolean attributes, self-closes void elements, and preserves data-* and aria-* attributes as-is. The output is JSX-ready source that you paste into your React component file and pass through your project's Babel or TypeScript compiler.

class is a reserved keyword in JavaScript. Because JSX is transpiled JavaScript, using class as a property name would conflict with the JavaScript class declaration syntax. React's DOM renderer requires className for the HTML class attribute. Similarly, for is a reserved loop keyword, so label elements use htmlFor in JSX. The converter handles both mappings automatically.

HTML inline styles are strings: style="color: red; margin-top: 8px". JSX requires style to be a JavaScript object with camelCased property names: style={{ color: "red", marginTop: 8 }}. The converter splits the style string on semicolons, camelCases each CSS property name, converts simple pixel values to numbers (8px → 8), and strips !important since it has no meaning in React inline styles.

React uses a standardised set of property names that differ from their HTML equivalents. Examples include tabindex → tabIndex, readonly → readOnly, maxlength → maxLength, colspan → colSpan, rowspan → rowSpan, crossorigin → crossOrigin, datetime → dateTime, formaction → formAction, contenteditable → contentEditable, spellcheck → spellCheck, autofocus → autoFocus, and allowfullscreen → allowFullScreen. ToolsSonic maps over 35 HTML attributes to their correct React DOM counterparts.

HTML event attributes like onclick, onchange, onsubmit, onfocus, and onblur are camelCased to their React equivalents: onClick, onChange, onSubmit, onFocus, onBlur. The converter supports 31 event mappings including mouse, keyboard, touch, pointer, scroll, wheel, animation, and transition events. Inline handler strings such as onclick="submitForm()" are never executed — they are replaced with a {/* TODO */} comment that flags the location for manual replacement.

In React, uncontrolled inputs that have a pre-set value should use defaultValue to set the initial value without making the input controlled. The converter maps value attributes on input and select elements to defaultValue, and textarea element content to the defaultValue prop, so the output is correct for uncontrolled component patterns. You can disable this with the value → defaultValue toggle.

Enabling TypeScript mode wraps the component as export const ComponentName: React.FC = () => (...) instead of the plain arrow function export. The download button changes from .jsx to .tsx. This gives you a typed starting point — add your own prop interface and import React from "react" before compiling. The component name is editable in the Name field.

A JSX component must return a single root element. When HTML has multiple top-level nodes, wrapping them in a <div> changes the DOM structure. A fragment <> … </> groups them without adding a real DOM node. When Wrap in fragment is enabled and the converted HTML has more than one top-level node, the converter automatically wraps them in a fragment.

A <style> tag inside a React component cannot use a plain stylesheet string. When the style tag option is enabled, the converter transforms <style> blocks to self-closing JSX with dangerouslySetInnerHTML={{ __html: `...` }}, matching the pattern React developers actually use.

When Wrap as component is enabled, the converter generates an export const ComponentName = () => (...) arrow function. The Name field lets you type any valid PascalCase identifier such as HeroSection, ProductCard, or NavBar. If the name starts with a lowercase letter or contains invalid characters they are auto-corrected. The default name is ConvertedMarkup.

HTML boolean attributes like disabled, required, hidden, readonly, multiple, and selected are valueless or self-valued. In JSX, boolean props are written without a value: disabled, required, hidden. The converter detects these attributes and omits the = value, producing valid JSX boolean syntax. checked on input elements is converted to defaultChecked for uncontrolled components.

HTML comments <!-- text --> are not valid inside JSX expressions. They must be written as JavaScript comments inside curly braces: {/* text */}. The converter maps every HTML comment to a JSX comment block. Double hyphens inside the comment are single-hyphenated to avoid issues with comment parsing.

Void elements are HTML elements with no closing tag: br, img, input, meta, link, hr, source, embed, area, base, col, param, track, and wbr. In JSX, these must be self-closing: <br />, <img src="…" />, <input type="text" />. The converter automatically self-closes all void elements to produce valid JSX.

React preserves data-* and aria-* attributes exactly as-is in lowercase without camelCasing. The converter keeps them unchanged. No mapping is applied, and they are never incorrectly camelCased.

HTML entities such as &amp;, &lt;, &gt;, and &quot; are decoded to their UTF-8 character equivalents when Decode entities is enabled. In JSX, text content can include literal Unicode characters directly. Curly braces in text are escaped to &#123; and &#125; to prevent JSX from interpreting them as expressions.

Yes. Open HTML reads a local .html or .htm file using the browser FileReader API. The file contents are loaded into the input panel and converted immediately, entirely in memory. The file is never sent to a server.

Yes. Click Download .jsx to save a converted.jsx file locally, or enable TypeScript mode and Wrap as component to get Download .tsx that saves a converted.tsx file. Copy JSX puts the output on the clipboard immediately. No server or account is required.

No. The output is JSX-ready source text — it is not compiled, executed, sanitized, or validated against React runtime rules. You must import React, add your event handlers, pass your props, and run the code through your project's Babel or TSC compiler and lint pipeline before it is ready to use.

The converter is completely free with no account required. All conversion runs locally in your browser using the native DOMParser API. No HTML is uploaded to any server, stored in localStorage, or retained after you close the tab.

HTML to JSX conversion changes attribute names, inline styles, events, boolean props, and void element syntax to produce React-compatible JSX. HTML escaping replaces characters like &, <, >, and " with HTML entity references so text is safe to display in a browser. The two operations are unrelated and serve different purposes.

After each conversion the tool records the document title or element count and a summary of mappings and warnings in an 8-item history list. History is stored only in page memory and disappears when you close or reload the tab.

What is HTML to JSX Converter?

An HTML to JSX converter transforms plain HTML markup into valid JSX syntax for React component files. It is one of the most common tasks every React developer faces when adopting a design, integrating a template, converting a static HTML prototype, or moving a CMS-rendered page into a React-powered application. Doing this by hand — renaming every class to className, every for to htmlFor, rewriting every style string as a JavaScript object, self-closing every void element — is slow, error-prone, and tedious at scale. A converter does it instantly.

ToolsSonic's HTML to JSX Converter runs entirely in your browser using the native DOMParser API. No HTML is uploaded to any server at any point. The converter walks the parsed DOM tree and re-serialises each node using JSX syntax rules, collecting mapping statistics, warnings, and diagnostic notes as it goes.

React Property Mappings, Style Objects, and Event Handlers

The converter handles over 35 React DOM property name translations: class → className, for → htmlFor, tabindex → tabIndex, readonly → readOnly, maxlength → maxLength, colspan → colSpan, rowspan → rowSpan, crossorigin → crossOrigin, datetime → dateTime, contenteditable → contentEditable, autofocus → autoFocus, and more. These are not guesses — they are the documented React DOM property names.

Inline styles are converted from CSS declaration strings to JavaScript objects. The converter camelCases each CSS property name (margin-top → marginTop), converts simple pixel values to numbers (8px → 8), and strips !important since it has no meaning in React inline styles. Style object output looks like style={{ marginTop: 8, color: "red" }} — ready to paste into a JSX file.

HTML event attributes (onclick, onchange, onsubmit, onkeydown, onfocus, onblur, and 25 more including pointer, touch, scroll, wheel, animation, and transition events) are camelCased to their React equivalents. Crucially, inline handler strings like onclick="submitForm()" are never executed — the converter replaces them with {/* TODO: replace with a React handler function */} comments that flag every location needing manual attention.

DefaultValue, Fragments, TypeScript, and Component Names

HTML inputs with value attributes are converted to defaultValue for uncontrolled React component patterns. checked on input elements becomes defaultChecked. Textarea inner content is converted to the defaultValue prop. These three mappings prevent common "controlled/uncontrolled component" React warnings that catch developers by surprise when copying HTML forms into React.

When HTML has multiple top-level nodes, wrapping them in a <div> changes the DOM unnecessarily. JSX fragments <> … </> group them without a DOM node. The converter automatically fragments multi-root HTML when the option is enabled.

The TypeScript toggle generates export const ComponentName: React.FC = () => (...) — the correct typed component signature — and changes the download to .tsx. The component name is fully editable via a text field. The style tag → dangerouslySetInnerHTML option converts <style> blocks to the React-required pattern.

Diagnostics, Statistics, and Privacy

Every conversion produces a live diagnostics panel listing which attributes were mapped, which event handlers need manual replacement (with the specific element and attribute named), and a reminder that the output is JSX-ready source — not compiled, not executed, not sanitized. The statistics panel shows 6 metrics: input bytes, JSX bytes, element count, mapping count, warning count, and fragment count. An 8-item session history records each conversion by title and metrics.

Common use cases

  • Converting a static HTML prototype into React JSX component files
  • Migrating a design system HTML template to a React or Next.js codebase
  • Converting HTML email markup to a React email component for react-email or MJML-React
  • Generating a TypeScript .tsx starting point from an HTML component
  • Converting CMS-rendered or Shopify Liquid HTML to React JSX
  • Quickly renaming class → className and for → htmlFor across large HTML blocks
  • Turning a Bootstrap HTML template into a React component with correct prop names
  • Debugging a React warning about controlled/uncontrolled inputs by converting value to defaultValue

Why use ToolsSonic's HTML to JSX Converter?

ToolsSonic's HTML to JSX Converter is the only free online tool that combines: live mode, TypeScript .tsx output, custom component name, defaultValue/defaultChecked for controlled inputs, textarea→defaultValue, style tag→dangerouslySetInnerHTML, 31-event map (including pointer/scroll/animation events), per-attribute warning diagnostics, 8-item session history, file upload, .jsx/.tsx download, and full dark mode — all browser-only with no upload, no account. transform.tools has no defaultValue, no file upload, no download, no diagnostics; React Magic has no TSX mode, no live mode, no dark mode; WebUtils has no visible mapping confirmation or diagnostics.

React Property Mapping Reference

HTML AttributeJSX PropNotes
classclassNameReserved JS keyword
forhtmlForReserved JS keyword
tabindextabIndexcamelCase
readonlyreadOnlycamelCase
maxlengthmaxLengthcamelCase
minlengthminLengthcamelCase
colspancolSpancamelCase
rowspanrowSpancamelCase
crossorigincrossOrigincamelCase
datetimedateTimecamelCase
http-equivhttpEquivcamelCase, hyphen removed
accept-charsetacceptCharsetcamelCase, hyphen removed
contenteditablecontentEditablecamelCase
autofocusautoFocuscamelCase
allowfullscreenallowFullScreencamelCase
formactionformActioncamelCase
enctypeencTypecamelCase
novalidatenoValidatecamelCase
value (input/select)defaultValueUncontrolled component
checked (input)defaultCheckedUncontrolled component
textarea contentdefaultValue propUncontrolled component
style="…"style={{ camelKey: value }}Object, px→number, !important stripped
data-*data-* (unchanged)React passes through as-is
aria-*aria-* (unchanged)React passes through as-is

JSX vs TSX — When to Use Each

Aspect.jsx.tsx
LanguageJavaScript + JSXTypeScript + JSX
Component signatureexport const X = () => (...)export const X: React.FC = () => (...)
Type checkingRuntime onlyCompile-time via TSC
Prop typesPropTypes (optional)Interface or type alias
When to useJS projects, prototypes, quick conversionTypeScript projects, component libraries
ToolsSonic outputDefault download: converted.jsxTSX toggle + component: converted.tsx
100% private — runs in your browser Instant — no server round-trip Free forever — no account needed

HTML Formatter

Editor's choice

Beautify HTML locally with configurable indentation, attribute wrapping, raw-text preservation, document outline, live mode, and instant download — all private, no upload.

HTML Beautifier

Editor's choice

Beautify dense or compressed HTML locally with indentation, line wrapping, attribute formatting, raw-text preservation, heading outline, live mode, and download — all private, no upload.

HTML Minifier

Editor's choice

Minify HTML locally by removing ordinary comments and unnecessary inter-tag whitespace while protecting pre, textarea, script, and style content. Compare byte savings, copy, and download the result privately.

HTML Entity Encode

Editor's choice

Encode HTML-sensitive characters and Unicode text as named, decimal, or hexadecimal entities. Preview safe source, copy or download output, and keep every conversion private in your browser.

HTML Editor

Editor's choice

Edit HTML with a live preview — synchronized source editor, WYSIWYG visual pane, sandboxed preview, 5 starter templates, format, minify, validate, find/replace, file import, and download. 100% in your browser.

JSON to TypeScript Interface

Editor's choice

Convert JSON to TypeScript interfaces, type aliases, or enums in your browser. Infer nested objects, arrays, unions, readonly modifiers, optional and nullable fields, safe names, and downloadable .ts definitions from any JSON sample.