HTML to JSX Converter
Turn pasted HTML or SVG into React-ready JSX with local parsing, attribute migration rows, style-object handling, and event warnings.- {{ warning }}
{{ result.output }}
| Source | JSX | Location | Detail | Copy |
|---|---|---|---|---|
| {{ row.source }} | {{ row.jsx }} | {{ row.location }} | {{ row.detail }} |
| Check | Status | Detail | Copy |
|---|---|---|---|
| {{ row.check }} | {{ row.status }} | {{ row.detail }} |
Introduction:
Moving markup into React usually fails at the small syntax borders rather than at the visible layout. A copied card, form, table, icon, or design export can look like ordinary HTML, yet JSX reads it as JavaScript syntax. That means familiar attributes, comments, self-closing tags, and inline behavior have to fit rules that are stricter than a browser's forgiving HTML parser.
JSX was built so markup can live beside JavaScript logic, but it is not a paste-anything version of HTML. Attribute names become property-like names, child content must form a valid expression, and many browser repairs that happen quietly in HTML become easier to miss once the snippet becomes component code. The conversion job is partly mechanical and partly judgment: syntax can be rewritten, but behavior, accessibility, and project fit still need review.
| Markup issue | Why it matters in JSX | Typical review cue |
|---|---|---|
| Reserved words | class and for conflict with JavaScript naming expectations and React DOM property names. |
Look for className and htmlFor. |
| Dashed names | Most DOM and SVG props use camelCase, while data-* and aria-* stay dashed. |
Check SVG attributes such as strokeWidth and preserved accessibility attributes. |
| Inline CSS | React style props are objects, not a single CSS declaration string. | Review property names, custom properties, vendor syntax, and values that should remain strings. |
| Inline events | HTML event attributes are strings; React event props expect functions. | Replace copied JavaScript with project-owned handlers. |
Markup conversions show up in several everyday frontend jobs: turning a static prototype into a component, copying CMS output into a migration branch, cleaning an SVG icon set, or moving legacy templates toward React. In each case, the useful result is not just code that resembles the original source. It is code whose changed parts are visible enough to inspect before it enters a build, test suite, or shared design system.
A converter cannot decide whether copied markup belongs in a React application. It can reduce the mechanical work, flag risky areas, and make the first review faster. The final decision still depends on the target project's component patterns, lint rules, accessibility checks, and security expectations.
How to Use This Tool:
Start with the markup source, choose the parsing path that matches it, then read the generated JSX beside the migration checks.
- Paste markup into
HTML source, drop text onto the textarea, or load one HTML, HTM, SVG, or TXT file withBrowse HTML. Files stay in the browser, and a file over 1 MB stops with a file-size warning. - Set
Source scopebefore reviewing output.Auto fragment or body contentsfits most snippets and full documents,Full document treekeeps document-level elements, andSVG/XML rootreports malformed SVG instead of repairing it as HTML. - Choose
JSX output shape.React function componentadds a function wrapper,React fragmentkeeps multiple roots grouped, andRaw JSX onlyreturns the converted markup without a component shell. - For component output, set
Component name. Use Advanced only when the target codebase needs a named export, no export, an explicit React import, a different quote style, or four-space indentation. - Pick the risky-syntax policies.
Inline stylescan become React style objects, remain as strings for manual review, or be omitted.Event attributescan become handler stubs, remain flagged strings, or be omitted.Commentscan become JSX comments or be removed. - If the summary reads
Input needs review, fix the parse message before copying anything. Common causes are empty input, malformed SVG/XML, or a dropped file that is not one of the accepted text formats. - Review the active JSX tab first, then open
Attribute MigrationandConversion Checks. Copy or download the JSX only after the warning rows match the risks you expected from the source.
Interpreting Results:
The summary count tells you how many element tags were converted and whether review notes were found. A clean summary means no known converter warning appeared for the selected options. It does not prove that the JSX compiles, matches project conventions, or is safe to render unchanged.
| Result area | What it gives you | What still needs review |
|---|---|---|
JSX Component, JSX Fragment, or JSX Markup |
The generated JSX in the selected shape, using the chosen indentation, quote, style, event, comment, import, and export settings. | Paste it into the real project and run the normal parser, linter, type checker, and component tests. |
Attribute Migration |
A row-by-row ledger of source attributes, JSX names or omissions, element locations, and conversion details. | Inspect rows for style, event attributes, SVG names, booleans, custom attributes, and unchanged attributes from unfamiliar markup. |
Conversion Checks |
Local processing status, parser mode, attribute changes, style policy, event policy, comment handling, output size, and warning text. | Stop on parse errors, preserved style strings, inline event warnings, omitted DOCTYPE, and raw text elements. |
JSON |
A structured snapshot of options, metrics, migration rows, checks, warnings, and generated JSX. | Use it as a handoff record. It is not a build result or a security report. |
Trust the output most when the JSX compiles in the destination project and the review tables show only expected changes. Treat copied inline JavaScript, raw text elements, unknown custom attributes, and preserved style strings as stop-and-read items even when the visual markup looks simple.
Technical Details:
HTML, SVG, and JSX share tag-shaped syntax, but they are interpreted by different rules. HTML parsing is tolerant: omitted closing tags, mixed case, void elements, and document wrappers can be repaired or normalized before a developer ever sees the tree. JSX is parsed as JavaScript, so the emitted markup has to be explicit enough to become valid expression syntax.
React DOM props mostly follow JavaScript and DOM property naming. That is why tabindex becomes tabIndex, maxlength becomes maxLength, and for becomes htmlFor. Accessibility and data attributes are exceptions that remain dashed because React preserves aria-* and data-* names for browser and assistive-technology semantics.
SVG adds another naming pass because many SVG attributes were historically written with dashes or namespaces. A JSX migration often changes stroke-width to strokeWidth, fill-rule to fillRule, and xlink:href to xlinkHref. The shape data may be unchanged, but the prop spelling determines whether React accepts the attribute cleanly.
Transformation Core:
The conversion is a structured transform rather than a numeric formula. The source is parsed into element, text, and comment nodes, then each node is printed back as JSX according to the selected output shape and syntax policies.
| Stage | Mechanism | Important limit |
|---|---|---|
| Parse source | HTML input uses the browser's HTML parser. SVG/XML mode uses XML-style parsing and reports a parser error when the markup is not well formed. | HTML repair can change the tree from the original text, especially around omitted tags and invalid nesting. |
| Select root nodes | Auto mode uses body children for ordinary documents, keeps an SVG root when the source begins as SVG, and can keep the full document tree when selected. | Document-level output is useful for review, but most React components should not contain DOCTYPE or page-level wrappers. |
| Print elements | Element names, attributes, text nodes, comments, empty nodes, and multiple roots are written as JSX-compatible markup. | Formatting choices such as indentation and quote style change readability, not the parsed source tree. |
| Migrate attributes | Known HTML, SVG, event, boolean, data, and aria names are converted, preserved, or omitted according to React syntax and selected policies. | Custom attributes and framework-specific attributes may need project review even when the converter preserves them. |
| Report checks | Migration rows, warning text, parser mode, counts, and generated length are collected for review. | The checks identify converter-known issues. They do not replace compiling, linting, testing, or sanitizing in the destination app. |
Attribute Mapping Reference:
| Source pattern | Typical JSX form | Reason |
|---|---|---|
class |
className |
React uses the DOM property name for CSS class assignment. |
for |
htmlFor |
The DOM property links a label or output element to a control. |
readonly, maxlength, tabindex |
readOnly, maxLength, tabIndex |
React DOM props use camelCase JavaScript-style names for many standard attributes. |
stroke-width, clip-rule, viewbox |
strokeWidth, clipRule, viewBox |
SVG attributes are normalized to React-compatible prop spelling. |
xlink:href, xml:space |
xlinkHref, xmlSpace |
Namespaced SVG/XML attributes are written without the colon in JSX prop syntax. |
data-*, aria-* |
unchanged dashed spelling | React preserves these families for custom data and accessibility metadata. |
disabled, checked, required |
disabled={true} or disabled |
HTML boolean attributes are true when present, regardless of a string value such as "false". |
onclick="save()" |
onClick={() => { save(); }} when handler stubs are selected |
React event props expect functions instead of HTML event strings. |
Worked Transformation Path:
A compact input such as <button class="primary" disabled onclick="save()">Save</button> passes through several intermediate decisions before it becomes JSX.
- The parser produces one
buttonelement with three attributes and one text node. classmaps toclassName, anddisabledbecomes a true boolean prop using the selected boolean style.onclickmaps toonClick. In handler mode, the original string is wrapped in a function stub and a warning is added for manual review.- The printed JSX keeps the visible text
Save, but the review table should still be checked before the handler is reused.
Advanced Tips:
- Use
SVG/XML rootfor icon sets when malformed markup should fail instead of being repaired as browser HTML. - Keep
Inline stylesset to object mode for React handoff, but choose preserved strings when the first job is auditing copied CSS before rewriting it. - Treat
Handler stubsas placeholders. Replace generatedonClick,onChange, and similar props with project-owned functions before committing. - Choose
Raw JSX onlywhen pasting into an existing component return statement, andReact function componentwhen the snippet needs a named copy-ready component shell. - Switch
Text whitespaceto preserved mode only when whitespace is meaningful, such as copied prose, code samples, SVG text, or preformatted fragments. - Use
Attribute Migrationas the audit trail forclassName,htmlFor, SVG camelCase props, booleans, omitted attributes, and unchanged custom attributes.
Privacy and Safety Notes:
The conversion runs in the browser for pasted text, dropped text, and accepted local files. The checks table reports Local processing when the source was parsed and formatted without sending the markup to a backend conversion service.
- Local conversion reduces exposure during the rewrite, but it does not sanitize markup for safe rendering.
- HTML parsed in an inert document can still become dangerous if unsafe scripts, event attributes, or URLs are later inserted into an active application.
- Generated handler stubs are review aids, not finished application behavior.
- Run the generated JSX through the destination project's formatter, linter, build, tests, and security review before using it with untrusted content.
Worked Examples:
Prototype card to component
A pasted pricing card with class="pricing-card", for="team-email", disabled, and style="margin-top: 16px; background-color: #f8fafc;" works well with React function component and style-object mode. JSX Component should show className, htmlFor, an explicit boolean prop, and a camelCased style object. Attribute Migration gives the audit trail for those changes.
SVG icon with strict parsing
An icon that starts with <svg viewBox="0 0 24 24"> and includes stroke-width="2" should use SVG/XML root when malformed SVG should fail loudly. A valid icon keeps its shape while Attribute Migration records changes such as strokeWidth, strokeLinecap, and fillRule. A missing closing tag changes the summary to Input needs review until the SVG is fixed.
Inline event found during migration
A legacy button with onclick="trackSignup('team')" can produce a handler stub in JSX Component. Conversion Checks then warns that the inline event needs code review. The right follow-up is to replace the stub with a named handler from the destination component, not to treat the copied string as production logic.
FAQ:
Can I paste the generated JSX straight into React?
Use it as a first migration draft. Check Attribute Migration and Conversion Checks, then compile, lint, and test the JSX in the project that will own it.
Why did valid HTML become different JSX?
JSX is stricter than HTML and uses React prop names. Tags are explicitly closed, class changes to className, for changes to htmlFor, and many SVG names become camelCase.
Why does an SVG show a parse error?
SVG/XML root uses XML-style parsing, so malformed SVG is reported instead of repaired. Fix the mismatched tag, invalid nesting, or unescaped character, then rerun the conversion.
Are local files uploaded?
Accepted HTML, HTM, SVG, and TXT files are read in the browser. Files over 1 MB are rejected, and the checks table reports local processing for the conversion.
What should I do with inline events?
Treat handler stubs and preserved event strings as review notes. Replace them with real React event handlers from your component code before committing.
Does conversion sanitize unsafe HTML?
No. The converter rewrites syntax and flags review items. It does not certify that copied markup is safe, accessible, or appropriate to render.
Glossary:
- JSX
- HTML-like syntax used inside JavaScript expressions, commonly with React components.
- React prop
- A named value passed to a React element, including DOM props such as
classNameandhtmlFor. - DOM tree
- The parsed structure of elements, text nodes, comments, and attributes produced from markup.
- Boolean attribute
- An HTML attribute whose presence means true, such as
disabled,checked, orrequired. - Void element
- An HTML element such as
input,img, orbrthat does not take child content in HTML syntax. - Fragment
- A JSX wrapper that groups multiple children without adding an extra DOM element.
- Handler stub
- A generated function-shaped placeholder that preserves copied inline event code for review.
- Parser error
- A message returned when SVG/XML input is not well formed enough to convert.
References:
- Writing Markup with JSX, React.
- Common components, React.
- Responding to Events, React.
- HTML Standard: Common microsyntaxes, WHATWG.
- DOMParser: parseFromString(), MDN Web Docs.