FormatterHQ

HTML to JSX Converter

Paste HTML and get JSX you can drop into a React component. Attributes, inline styles, void elements, comments and event handlers are converted for you.

Input HTML
Output JSX
Ready.

How to use the HTML to JSX Converter

  1. Paste your HTML snippet or template into the input editor.
  2. Choose the indentation and, if you like, wrap the result in a named function component.
  3. Run the conversion to get JSX with React attribute names and style objects.
  4. Copy the JSX into your component and replace static values with props or state.

Why HTML needs converting to JSX

JSX looks like HTML, but it compiles to JavaScript function calls, so a handful of HTML habits break it. class is a reserved word in JavaScript, inline styles must be objects instead of strings, every element must be closed, and comments use a different syntax. Converting a large template by hand is tedious and error-prone; this HTML to JSX converter parses your markup with the browser's HTML parser and rewrites it correctly in one step.

Example

<div class="card" id="profile">
  <!-- Profile card -->
  <img src="/avatar.png" alt="Avatar" width="64">
  <label for="bio">Bio</label>
  <textarea id="bio" maxlength="200" readonly>Hello!</textarea>
  <h2 style="color: #333; font-size: 20px; margin-top: 0">Ada</h2>
  <button onclick="follow()">Follow</button>
</div>

becomes:

<div className="card" id="profile">
  {/* Profile card */}
  <img src="/avatar.png" alt="Avatar" width="64" />
  <label htmlFor="bio">Bio</label>
  <textarea id="bio" maxLength="200" readOnly defaultValue={"Hello!"} />
  <h2 style={{ color: '#333', fontSize: '20px', marginTop: 0 }}>Ada</h2>
  <button onClick={(event) => { follow() }}>Follow</button>
</div>

When the input has more than one top-level element, the output is wrapped in a fragment (<>…</>), because a component must return a single root.

What the converter changes

  • Attribute names – class → className, for → htmlFor, and dozens of others such as tabindex → tabIndex, colspan → colSpan, srcset → srcSet and SVG's viewbox → viewBox. Hyphenated SVG attributes like stroke-width become camelCase; data-* and aria-* stay as they are.
  • Inline styles – the CSS string becomes an object with camelCase keys. Plain numbers stay numbers, everything else becomes a string, and CSS custom properties keep their '--name' keys.
  • Void elements – <img>, <br>, <input> and friends are self-closed.
  • Form defaults – value and checked on inputs become defaultValue and defaultChecked, which keeps the fields uncontrolled so React does not warn about a missing onChange.
  • Event handlers – onclick becomes onClick with the original code wrapped in an arrow function.
  • Text – curly braces in text are escaped as {'{'}, and whitespace between inline elements is preserved with {" "}.
  • Scripts and styles – contents of <style> and <script> become template literals so special characters survive.

Options

  • Component wrapper – wraps the JSX in export default function MyComponent() { return (…); }. The name must start with an uppercase letter, as React requires for components.
  • Indentation – two spaces, four spaces or tabs to match your code style.

After converting

The output is a faithful, static translation. You will usually want to replace inline onclick code with real handler functions, move repeated markup into .map() loops and lift inline styles into CSS modules or your styling library. Run the result through the React formatter if you want Prettier-style formatting.

Going the other way, or working with other template languages? Try HTML to Pug, or tidy the original markup first with the HTML formatter.

Privacy

Parsing and conversion run in your browser. Your markup is not uploaded, which makes the tool safe for code from private projects.

Frequently asked questions

Why does React use className instead of class?
JSX is compiled to JavaScript, where class is a reserved keyword. React therefore uses the DOM property name className, just as it uses htmlFor instead of for.
Does the converter create a full React component?
Only if you enable the component option, which wraps the JSX in an exported function component. Otherwise you get the JSX markup to paste into an existing component.
What happens to inline event handlers like onclick?
They are renamed to React’s camelCase events, such as onClick, and the original code is wrapped in an arrow function. You will usually want to replace it with a proper handler function.
Can I convert a full HTML page with head and body?
You can, but React components normally render only the body content. Convert the part inside the body element, and manage the document head with your framework instead.
Does it work for SVG icons?
Yes. SVG attributes such as viewBox, stroke-width and xlink:href are converted to their JSX equivalents (viewBox, strokeWidth, xlinkHref).

Last updated September 26, 2026

Related tools

SVG to JSX / React Component Turn SVG markup into a React component: camelCase attributes, className, style objects and {...props}, with optional TypeScript. BBCode to HTML Converter Convert forum BBCode such as [b], [url], [quote], [list] and [code] into clean, safe HTML markup instantly. CSV to HTML Table Converter Convert CSV to HTML online for free. Get clean table markup with a live preview. Excel to HTML Table Converter Convert Excel to HTML online for free. Get clean table markup with a live preview. HTML Entities to Text Turn HTML entities (named, decimal and hex) back into plain Unicode text. HTML to BBCode Converter Convert HTML into forum-friendly BBCode: bold, links, images, lists, quotes, tables, code blocks and inline colours. HTML to PHP Converter Convert HTML into PHP echo statements, a string variable or a heredoc block with every quote and dollar sign safely escaped. HTML to Pug Converter Convert HTML to Pug template syntax: indentation-based tags, #id and .class shortcuts, attributes and text blocks. HTML to Text Converter Extract readable plain text from HTML: keeps paragraphs, headings, lists and tables, drops tags, scripts and styles. Hyperlink Generator Generate a hyperlink as HTML, Markdown, BBCode and plain text at once - ready for websites, READMEs, forums and e-mails. Jade to HTML Converter Render legacy .jade templates to HTML and find the deprecated Jade syntax to fix before moving to Pug or plain HTML. Mailto Link Generator Create mailto: links with pre-filled recipients, CC, BCC, subject and body — correctly URL-encoded, with the HTML <a> tag.