HTML to JSX

Convert HTML to React/JSX

Paste your HTML here...
Loading editor...
Loading editor...

HTML to JSX Converter — Transform HTML to React JSX Syntax

Understanding the Basics

JSX (JavaScript XML) is a syntax extension to JavaScript used in React (and compatible frameworks like Preact and Solid) that allows HTML-like markup to be written directly in JavaScript files. While JSX closely resembles HTML, several important differences require transformation when converting raw HTML to JSX for use in React components. The most significant differences: JSX uses className instead of class (since class is a reserved JavaScript keyword), htmlFor instead of for in label elements, and camelCase for all HTML attributes that have hyphens (tabIndex instead of tabindex, readOnly instead of readonly, onClick instead of onclick). Inline styles in HTML use semicolon-separated strings (style="color:red;font-size:16px") but JSX requires JavaScript object literals (style={{color: 'red', fontSize: '16px'}}) with camelCased property names. Self-closing tags are required in JSX for void elements: input, img, br, hr must be written as <input />, <img />, <br /> and <hr />. By automating this process, frontend developers can avoid manual, error-prone edits during copy-paste operations. HTML comments syntax (<!-- -->) is not valid JSX; JSX uses JavaScript block comments inside expressions ({/* comment */}). Converting HTML templates to JSX is a daily task for React developers integrating designs from HTML/CSS designers or porting static HTML prototypes to React applications. Our converter handles all these transformations automatically.

How to Use the Tool

  1. Paste your HTML code into the input editor.
  2. The tool transforms HTML attributes to JSX equivalents: class → className, for → htmlFor, tabindex → tabIndex.
  3. Inline style strings are converted to JSX style objects with camelCased property names.
  4. Void elements are self-closed: <input> → <input />, <br> → <br />, <img> → <img />.
  5. HTML comments are converted to JSX comments: <!-- text --> → {/* text */}.

Key Features & Specifications

  • Converts class → className, for → htmlFor, and all other HTML-to-JSX attribute name changes
  • Transforms inline style strings to JSX style objects with camelCased CSS properties
  • Self-closes void elements (input, img, br, hr, meta, link) per JSX requirements
  • Converts HTML comments to JSX expression comments ({/* ... */})
  • Wraps output in a React function component shell if the "Wrap in component" option is enabled

Frequently Asked Questions (FAQ)

Q:Why does JSX use className instead of class?
"class" is a reserved keyword in JavaScript for ES6 class declarations. Since JSX is transpiled to JavaScript function calls, using "class" as an attribute name would cause a syntax conflict. React chose "className" to match the browser's DOM property name (element.className) for consistency with the JavaScript API.
Q:How are event handlers like onclick converted to JSX?
HTML event attributes like onclick="handler()" become camelCase React event props: onClick={handler}. In JSX, event handlers are JavaScript function references (or arrow functions), not inline strings. The HTML string onclick="alert('hi')" becomes onClick={() => alert('hi')} in JSX.
Q:What about data-* and aria-* attributes?
data-* attributes (data-id, data-value) remain unchanged in JSX — they keep their hyphenated names exactly as in HTML. aria-* attributes (aria-label, aria-hidden) also remain hyphenated in JSX. Only standard HTML attributes are renamed to camelCase.