ToolDeck

HTML to JSX

Convert HTML to JSX for React — class→className, style strings→objects

Try an example

HTML Input

JSX Output

Runs locally · Safe to paste secrets
JSX output will appear here…

What Is HTML to JSX Conversion?

HTML to JSX conversion is the process of transforming standard HTML markup into JSX syntax that React components can render. JSX looks similar to HTML but follows JavaScript naming conventions and rules. Attributes like class become className, for becomes htmlFor, and inline style strings are replaced with JavaScript objects. These changes are required because JSX compiles to React.createElement() calls, where attribute names must match the DOM API property names rather than HTML attribute names.

The mapping between HTML attributes and JSX props is defined by React's DOM elements documentation. React uses camelCase for multi-word attributes (tabindex becomes tabIndex, maxlength becomes maxLength) because JavaScript identifiers cannot contain hyphens. Self-closing tags like <img>, <br>, and <input> must include a trailing slash in JSX (<img />) since JSX follows XML rules where every tag must be explicitly closed.

Beyond attribute renaming, HTML to JSX conversion also handles inline styles and comments. HTML style attributes use CSS syntax as a string (style="color: red; font-size: 14px"), while JSX expects a JavaScript object with camelCase property names (style={{ color: 'red', fontSize: '14px' }}). HTML comments (<!-- -->) become JSX expression comments ({/* */}). Missing any of these transformations produces runtime errors or silent rendering bugs in React applications.

Why Use an HTML to JSX Converter?

Manually renaming attributes and rewriting style strings across dozens of HTML elements is slow and error-prone. A converter handles every transformation at once, letting you paste HTML from any source and get valid JSX in seconds.

Instant conversion
Paste any HTML snippet and get JSX output immediately. The converter handles class, for, style, event handlers, boolean attributes, and self-closing tags in a single pass.
🔒
Privacy-first processing
All conversion runs locally in your browser. Your HTML never leaves the page, so you can safely convert markup containing internal code, API endpoints, or sensitive content.
📋
No account or setup
Open the page and start converting. No login required, no npm packages to install, no build step to configure. Works on any device with a modern browser.
🔧
Complete attribute coverage
Converts all standard HTML-to-JSX attribute mappings including className, htmlFor, tabIndex, readOnly, autoComplete, and 20+ others. Also handles onclick to onClick event handler renaming.

HTML to JSX Use Cases

Frontend developer: migrating templates
When moving an existing HTML page or component into a React project, paste the markup into the converter instead of manually hunting for class and for attributes across hundreds of lines.
Backend engineer: embedding HTML emails
Email templates are authored in plain HTML. When rendering them inside a React admin dashboard or preview component, convert the HTML to valid JSX to avoid className and style syntax errors.
DevOps: converting dashboard widgets
Monitoring dashboards often use HTML snippets for custom widgets. Convert these to JSX when integrating them into a React-based internal tools platform like Retool or a custom admin panel.
QA engineer: reproducing bug reports
When a bug report includes raw HTML output, convert it to JSX to quickly render it inside a React test harness or Storybook story for visual inspection and debugging.
Designer: prototyping from HTML mockups
Design tools like Figma export HTML/CSS. Convert the exported markup to JSX to drop it directly into a React prototype without manual attribute cleanup.
Student: learning React syntax
Compare HTML input with JSX output side by side to understand which attributes change and why. Seeing the transformation makes the React naming conventions easier to memorize than reading documentation alone.

HTML to JSX Attribute Mapping Reference

The table below lists the HTML attributes that change when converted to JSX. Attributes not listed here (id, src, href, alt, placeholder, etc.) remain unchanged because their HTML names already match the corresponding DOM API property names.

HTML AttributeJSX PropNotes
classclassNameReserved word in JavaScript
forhtmlForReserved word in JavaScript
tabindextabIndexcamelCase convention
readonlyreadOnlycamelCase convention
maxlengthmaxLengthcamelCase convention
minlengthminLengthcamelCase convention
cellpaddingcellPaddingcamelCase convention
cellspacingcellSpacingcamelCase convention
rowspanrowSpancamelCase convention
colspancolSpancamelCase convention
enctypeencTypecamelCase convention
autocompleteautoCompletecamelCase convention
autofocusautoFocuscamelCase convention
autoplayautoPlaycamelCase convention
contenteditablecontentEditablecamelCase convention
crossorigincrossOrigincamelCase convention
novalidatenoValidatecamelCase convention
allowfullscreenallowFullScreencamelCase convention
spellcheckspellCheckcamelCase convention
http-equivhttpEquivHyphen removed, camelCase
onclickonClickEvent handler camelCase
onchangeonChangeEvent handler camelCase
onsubmitonSubmitEvent handler camelCase

Inline Style Conversion: HTML vs JSX

Inline styles are the most error-prone part of HTML to JSX conversion because both the value format and the property names change:

HTML style attribute
A string of CSS declarations separated by semicolons. Property names use kebab-case (background-color, font-size, border-radius). Values are always strings, including numeric values with units.
<div style="background-color: #fff;
  font-size: 14px;
  margin-top: 10px;">
JSX style prop
A JavaScript object with camelCase property names (backgroundColor, fontSize, borderRadius). String values are quoted. Unitless numeric values (lineHeight, opacity, zIndex, flexGrow) can be plain numbers.
<div style={{
  backgroundColor: '#fff',
  fontSize: '14px',
  marginTop: 10
}}>

Code Examples

These examples show how to convert HTML to JSX programmatically in different languages and environments. Each covers attribute renaming, style conversion, and self-closing tag handling.

JavaScript (DOM API)
// Simple attribute conversion using string replacement
function htmlToJsx(html) {
  return html
    .replace(/\bclass=/g, 'className=')
    .replace(/\bfor=/g, 'htmlFor=')
    .replace(/\btabindex=/g, 'tabIndex=')
    .replace(/<!--([\s\S]*?)-->/g, '{/*$1*/}')
}

htmlToJsx('<div class="box" tabindex="0"><!-- note --></div>')
// → '<div className="box" tabIndex="0">{/* note */}</div>'
JavaScript (html-react-parser)
import parse from 'html-react-parser'

// Parse HTML string into React elements (handles all JSX rules)
const element = parse('<div class="card"><img src="photo.jpg" alt="Photo"></div>')
// Returns: React.createElement('div', { className: 'card' },
//   React.createElement('img', { src: 'photo.jpg', alt: 'Photo' }))

// With custom element replacement
const options = {
  replace(domNode) {
    if (domNode.name === 'img') {
      return <OptimizedImage src={domNode.attribs.src} alt={domNode.attribs.alt} />
    }
  }
}
const custom = parse('<img src="photo.jpg" alt="Photo">', options)
Python (BeautifulSoup)
from bs4 import BeautifulSoup
import re

ATTR_MAP = {
    'class': 'className', 'for': 'htmlFor',
    'tabindex': 'tabIndex', 'readonly': 'readOnly',
    'maxlength': 'maxLength', 'autocomplete': 'autoComplete',
}

def html_to_jsx(html: str) -> str:
    """Convert HTML attribute names to JSX equivalents."""
    for html_attr, jsx_attr in ATTR_MAP.items():
        html = re.sub(rf'\b{html_attr}=', f'{jsx_attr}=', html)
    # Convert HTML comments to JSX comments
    html = re.sub(r'<!--(.*?)-->', r'{/*\1*/}', html)
    return html

print(html_to_jsx('<label for="email" class="field">Email</label>'))
# → '<label htmlFor="email" className="field">Email</label>'
Go
package main

import (
    "fmt"
    "strings"
)

var attrMap = map[string]string{
    "class=":    "className=",
    "for=":      "htmlFor=",
    "tabindex=": "tabIndex=",
    "readonly":  "readOnly",
}

func htmlToJSX(html string) string {
    result := html
    for old, new := range attrMap {
        result = strings.ReplaceAll(result, old, new)
    }
    // Convert comments
    result = strings.ReplaceAll(result, "<!--", "{/*")
    result = strings.ReplaceAll(result, "-->", "*/}")
    return result
}

func main() {
    html := `<div class="wrapper"><input readonly tabindex="1"></div>`
    fmt.Println(htmlToJSX(html))
    // → <div className="wrapper"><input readOnly tabIndex="1"></div>
}

Frequently Asked Questions

What is the difference between HTML and JSX?
JSX is a syntax extension for JavaScript used by React. It looks like HTML but compiles to React.createElement() calls. The main differences are: class becomes className, for becomes htmlFor, inline styles use JavaScript objects instead of CSS strings, and all tags must be explicitly closed (including void elements like <img />). JSX also allows embedding JavaScript expressions inside curly braces.
Why does React use className instead of class?
The word 'class' is a reserved keyword in JavaScript. Since JSX compiles to JavaScript function calls, using 'class' as a prop name would cause a syntax error. React chose 'className' because it matches the DOM API property name (element.className) that JavaScript already uses to read and set CSS classes on DOM elements.
Do I need to convert HTML to JSX manually?
No. You can use an online converter like this tool, or automate it with libraries such as htmltojsx (npm) or html-react-parser. For large-scale migrations, tools like codemod or jscodeshift can transform entire codebases. Manual conversion is only practical for small snippets of a few lines.
How are inline styles handled in JSX?
In JSX, the style attribute accepts a JavaScript object, not a CSS string. Property names use camelCase (backgroundColor instead of background-color). Values are strings by default, but certain numeric properties like lineHeight, opacity, and zIndex accept plain numbers without units. The double curly braces in style={{ color: 'red' }} are not special syntax: the outer braces are a JSX expression, and the inner braces are a JavaScript object literal.
Can I use HTML comments in JSX?
No. HTML comments (<!-- comment -->) are not valid in JSX. Use JavaScript block comments wrapped in curly braces instead: {/* comment */}. This converter handles the transformation automatically. JSX comments must be inside a parent element, not at the top level of a component return.
Which HTML attributes stay the same in JSX?
Most HTML attributes keep their original names in JSX. Common examples include id, src, href, alt, type, name, value, placeholder, disabled, hidden, and all data-* and aria-* attributes. Only attributes whose HTML name differs from the DOM API property name need to change: class to className, for to htmlFor, and multi-word attributes that switch from lowercase to camelCase.
Is dangerouslySetInnerHTML the same as converting HTML to JSX?
No. dangerouslySetInnerHTML bypasses React's rendering and injects raw HTML directly into the DOM, which risks XSS vulnerabilities. Converting HTML to JSX produces actual React elements that go through React's virtual DOM and are safe by default. Use HTML-to-JSX conversion for static markup you control. Use dangerouslySetInnerHTML only when you must render trusted HTML from an external source that cannot be converted to JSX.