HTML to JSX
Convert HTML to React JSX online instantly. Free HTML to JSX converter that transforms class to className and fixes attributes.
Conversions Applied
Attributes
class→classNamefor→htmlFortabindex→tabIndexmaxlength→maxLengthonclick→onClick
Syntax
- Self-closing tags get
/> - Inline styles become objects
- Comments become JSX comments
About HTML to JSX Converter
Convert HTML to React JSX syntax. Handles attribute conversion (class to className), self-closing tags, inline styles to objects, and event handler naming conventions.
How to Use HTML to JSX
Paste your HTML
Paste any HTML markup into the input editor. Components, layouts, fragments, or full pages all work — the converter handles common HTML patterns.
View JSX output
The JSX-compatible version appears instantly: 'class' → 'className', 'for' → 'htmlFor', self-closing tags added, inline styles converted to objects.
Configure options
Choose whether to wrap output in a fragment (<>...</>), how to handle event handlers, and inline style format.
Paste into your component
Click Copy and paste directly into your React component's return statement. May need minor adjustments for event handlers, conditional rendering, or component imports.
When to Use HTML to JSX
Migrating HTML templates to React
When porting an existing HTML template (from a designer, an existing web page, an email template) into a React component, the JSX-syntax differences are tedious to fix manually. The converter handles class→className, for→htmlFor, self-closing tags, and inline style conversion automatically.
Bringing static designs into Next.js apps
Designers often deliver HTML mockups. To integrate into a Next.js or React app, you need JSX. Convert the HTML to JSX, then wrap in a function component, replace static data with props, and add interactivity. The conversion is the boring boilerplate work; converter saves 80% of it.
Converting React Native syntax (similar but different)
React Native uses JSX with HTML-like elements (<View>, <Text>) instead of HTML tags. While not exactly HTML→JSX, the conversion logic is similar (camelCase props, self-closing tags). Use as a starting point, then replace HTML elements with React Native equivalents.
Updating older React code (non-JSX) to modern JSX
Older React used React.createElement() function calls. While modern code uses JSX universally, you may encounter codebases mixing both. Converting the HTML-like markup in createElement calls to actual JSX modernizes the codebase.
HTML to JSX Examples
Basic class→className
<div class="container"><label for="name">Name</label></div><div className="container"><label htmlFor="name">Name</label></div>Two key JSX changes: 'class' is a reserved keyword in JS, so JSX uses 'className'. 'for' is also reserved (used in for loops), so JSX uses 'htmlFor'. The converter applies both substitutions automatically.
Self-closing tags
<br><hr><img src="x.png" alt="X"><br/><hr/><img src="x.png" alt="X"/>JSX requires all tags to be closed. Void elements that HTML allows to be unclosed (<br>, <hr>, <img>, <input>, <link>, <meta>) need explicit slashes (<br/>). The converter adds them where needed.
Inline style object syntax
<div style="color: red; font-size: 14px; margin-top: 10px">Hello</div><div style={{color: "red", fontSize: "14px", marginTop: "10px"}}>Hello</div>HTML's CSS string becomes a JS object in JSX. Property names switch from kebab-case (font-size) to camelCase (fontSize). Values are JS strings (quoted). Outer {{ }} = JSX expression containing object literal.
Tips & Best Practices for HTML to JSX
- 1.After conversion, add React-specific features: state (useState), effects (useEffect), props, event handlers. The JSX gives you the structure; React component logic comes from your code.
- 2.If your HTML has SVG, the converter handles svg-specific attribute conversion (xmlns:xlink → xmlnsXlink). SVG in JSX has its own quirks; verify the converted SVG renders correctly.
- 3.Watch for HTML5 boolean attributes: <input disabled> in HTML stays valid in JSX as disabled (no value needed). Some converters change to disabled={true}, which works but is more verbose.
- 4.Lists from .map() in JSX need 'key' props. The converter doesn't add keys — they require knowing what's unique in your data. Add them manually after conversion.
- 5.If the HTML has data-* or aria-* attributes, they're preserved as-is (no camelCase conversion since they have hyphens). Custom attributes (data-foo, aria-label) work identically in JSX.
- 6.For very complex HTML (lots of inline scripts, custom elements, web components), the converter handles structure but you'll need to manually adapt the dynamic behavior. Web components in particular need careful integration with React's lifecycle.
Frequently Asked Questions
Related Tools
JSON to TypeScript
Generate TypeScript interfaces from JSON data online. Free JSON to TypeScript converter with nested types and optional properties.
TOML to JSON Converter
Convert TOML configuration files to JSON format instantly. Free online TOML to JSON converter with syntax validation and formatting.
JSON to Python Dataclass
Convert JSON to Python dataclass or Pydantic model definitions. Auto-generate typed Python classes from JSON data. Free converter.
JSON to Rust Struct
Convert JSON to Rust struct definitions with serde derive macros. Auto-generate typed Rust structs from JSON data. Free converter.
Markdown to HTML
Convert Markdown to HTML online with live preview. Free Markdown to HTML converter supporting tables, code blocks, and lists.
HTML to Markdown
Convert HTML to Markdown format online instantly. Free HTML to Markdown converter preserving headings, links, images, and lists.