HTML to JSX Converter - Convert HTML to React
Turn HTML into valid JSX
Markup pasted into a React component from a template or an old page usually fails on the first compile: class
instead of className, an unclosed <br>, a style string. Paste HTML on the left and get JSX on
the right. Your browser parses the HTML, so unclosed tags are fixed up the same way a real page would fix them.
What gets converted
classbecomesclassNameandforbecomeshtmlFor.- Inline
stylestrings become style objects with camelCase property names. CSS variables stay quoted. - Void and empty elements such as
<br>,<img>and<input>are self-closed. - Attributes like
tabindex,readonly,maxlengthandautocompleteget their React names. - SVG attributes such as
stroke-widthandxlink:hrefbecomestrokeWidthandxlinkHref. - Event attributes such as
onclickbecomeonClickwith an arrow function. - HTML comments become JSX comments.
- Boolean attributes such as
disabled=""become plaindisabled. - Several top-level elements are wrapped in a fragment,
<>...</>.
How to use it
Paste HTML and the JSX appears as you type. Tick Wrap in a component to get an export default function you can
save as its own file. The name must start with a capital letter, or React treats <loginForm /> as an HTML
tag. Leave it unticked to get bare JSX for an existing component's return. Raw SVG icons convert the same way.
Example
Input:
<form class="login" onsubmit="return check()">
<!-- Email field -->
<label for="email">Email</label>
<input type="email" id="email" tabindex="1" autofocus>
<p style="color: #666; font-size: 12px">We never share your <b>email</b>.</p>
<button class="btn btn-primary" disabled>Sign in</button>
</form> Output (wrapped in a component called LoginForm):
export default function LoginForm() {
return (
<form className="login" onSubmit={(event) => { return check() }}>
{/* Email field */}
<label htmlFor="email">Email</label>
<input type="email" id="email" tabIndex="1" autoFocus />
<p style={{ color: "#666", fontSize: "12px" }}>We never share your <b>email</b>.</p>
<button className="btn btn-primary" disabled>Sign in</button>
</form>
);
} Whitespace is kept correct
JSX drops line breaks between text and tags, so Hello on one line and <b>world</b> on
the next renders as Helloworld. To avoid that, any element that mixes text with inline tags is written on a
single line, as the <p> above shows.
After converting
Replace inline event code with real handlers and decide which inputs need state. For a full page, paste the contents of
<body> rather than the whole document. tabindex="1" comes out as the string
tabIndex="1", which React accepts, though {1} is more usual. To tidy the source first, use
the HTML formatter.
Related Tools
Epoch / Unix Timestamp Converter
Convert between Unix epoch timestamps and human-readable dates.
Regex Tester
Test regular expressions against text with match highlighting.
UUID Generator
Generate random v4 UUIDs for use in databases and APIs.
Colour Converter
Convert colours between HEX, RGB, and HSL formats.