What changes
- Attribute names:
class→className,for→htmlFor,tabindex→tabIndexand the other camelCase names React uses.data-*andaria-*stay as they are. - Styles:
style="font-size: 12px"→style={{ fontSize: "12px" }}; vendor prefixes and custom properties (--accent) are handled. - Form fields:
valueandcheckedbecomedefaultValueanddefaultChecked, so React treats the fields as uncontrolled instead of warning; a<textarea>'s text becomes itsdefaultValue. - Tags and text: void tags such as
<br>become<br />, comments become{/* … */}, and{,}and>in text are escaped. Several top-level elements are wrapped in a fragment<>…</>. - Inline event handlers such as
onclick="save()"can't be converted safely; they become empty functions with the original code in a comment.
How to use the HTML to JSX
- Paste HTML, or press Sample.
- Turn on Component to wrap it in a React component, and choose its name, props and TypeScript.
- Read the notes for anything that needs attention.
- Copy the JSX or download it.
Examples
Attributes, styles and form fields
<label for="email" class="label">Email</label><input id="email" type="email" value="ada@example.com" required style="margin-top: 4px"><>
<label htmlFor="email" className="label">
Email
</label>
<input
id="email"
type="email"
defaultValue="ada@example.com"
required
style={{ marginTop: "4px" }}
/>
</>
Two top-level elements, so they're wrapped in a fragment.
A component
<section class="hero"><h1>Hello</h1><!-- CTA --><a href="/start" class="btn">Start</a></section>export default function Hero() {
return (
<section className="hero">
<h1>Hello</h1>
{/* CTA */}
<a href="/start" className="btn">
Start
</a>
</section>
);
}
Options
- Component
- Wrap the JSX in
export default function <Name>() { return (…); }. - Spread props
- Pass the component's props to its root element with
{...props}. - TypeScript
- Type the props as
React.ComponentProps<"…">for the root element.
Limitations
- Inline scripts are removed and inline event handlers emptied: move behaviour into React code.
- Template syntax (Handlebars, Liquid, Blade) isn't understood and is converted as text.
Frequently asked questions
Is my HTML uploaded?
No. The conversion and formatting run in your browser; nothing you paste is sent anywhere.
Why className instead of class?
JSX compiles to JavaScript, where class is a reserved word, so React uses the DOM property names: className and htmlFor.
Why did value become defaultValue?
In React, value makes a field controlled: it can only change through state. defaultValue sets the initial value and lets the user edit it, which matches how the HTML behaved.
Can it convert SVG icons?
Yes, but the SVG to JSX converter adds options for icons, such as removing the size and spreading props.