How to convert JSX to HTML
JSX is JavaScript that looks like HTML, so a browser cannot read it directly. To convert jsx to html, the tool reads the JSX, renames the attributes back to their HTML names, writes style objects as style strings and prints plain markup. Anything that depends on running the code is marked instead of guessed.
The built-in example is a Card component with a style object, a comment, a label, a checkbox and a button. The result is:
<div class="card" style="padding: 16px; background-color: white">
<!-- header -->
<h2 class="card__title">{{title}}</h2>
<p>Read the <a href="/docs" target="_blank" rel="noreferrer">docs</a> first.</p>
<label for="agree">Agree</label>
<input id="agree" type="checkbox" checked disabled tabindex="0">
<button class="{{items.length ? "on" : "off"}}">Save</button>
</div>The status line reports 5 attributes renamed and 2 dynamic values, and the panel lists them as Line 5 and Line 11.
What changes when you convert JSX to HTML
- Attribute names.
classNamebecomesclass,htmlForbecomesfor, andtabIndex,colSpan,maxLengthand similar names return to lowercase. - Style objects.
{ padding: 16, backgroundColor: "white" }becomespadding: 16px; background-color: white. Numbers get px, except unitless properties such as opacity and z-index. - Default props.
defaultValuebecomesvalueanddefaultCheckedbecomeschecked. - Boolean attributes.
disabledstays as a bare attribute, anddisabled={false}is left out. - Self-closing tags.
<br />becomes<br>, and<div />becomes<div></div>, because HTML does not allow a self-closed div. - Comments. A JSX comment in braces becomes an HTML comment.
- SVG. Names such as
strokeWidthgo back tostroke-width. For a whole SVG in JSX, JSX to SVG builds a standalone file.
Dynamic values, components and handlers
HTML cannot hold JavaScript expressions, so the converter handles each kind of dynamic part openly:
- Expressions such as
{title},{items.map(...)}orclassName={cls}become{{ title }}-style placeholders. Turn the option off to remove them. Each one is listed with the line it came from. - Literal expressions, such as
{"text"},{42}and template strings without variables, are written as plain text.{null},{false}and{undefined}disappear, as they do in React. - Event handlers such as
onClickare removed and listed, because HTML has no equivalent that carries a function. - Components with a capital letter, such as
<Card>, are kept as written and listed. The tool cannot know what they render. - Props spreads,
{...props}, are removed. Conditional parts such as{open && <p />}are marked as dynamic, not expanded.
JSX from a whole file
You can paste an entire component file. The tool skips imports, hooks, types and strings, and starts at the first piece of JSX, such as the one after return ( or after =>. TypeScript syntax like useState<string> is not mistaken for a tag. If the file holds more than one component, only the first JSX is converted, and a note says how many more it found.
To go the other way, HTML to JSX converts markup into JSX with renamed attributes and style objects. HTML Decoder and Remove HTML Tags help when the HTML you end up with needs entities decoded or tags stripped.
Can a React component be rendered to real HTML?
Not here. This tool converts the markup in the source. It does not run your code, so it cannot call hooks, read props, run conditions or expand components. A page rendered by React at run time can be saved with a browser, or generated with a server-side rendering function such as renderToString in your project.
Limits
- JSX inside an attribute value, as in
icon={<Icon />}, is not read and the tool says so. - Whitespace follows JSX rules: lines of text are joined with one space, and spaces at the start and end of a line are dropped.
- Only the first JSX in a file is converted.
Your code is converted in your browser. It is not uploaded or stored. See the Privacy Policy for details.