Skip to content

TSX to HTML

✨ Converts as you type 0 lines · 0 B

HTML

Paste a React component on the left

Plain HTML will appear here
Nothing to convert yet

TSX to HTML Converter – Turn a React Component into HTML

What Is TSX, and Why Turn It Back into HTML?

TSX is the file format for React components written in TypeScript. The markup part looks a lot like HTML, but it’s mixed with JavaScript: className instead of class, style objects, curly braces full of variables, and lists built with .map(). A browser can’t use that as a page on its own.

Sometimes you just want the plain HTML: to drop a component into a static page or a CMS, to build an email, to hand a designer something they can open, or to check what a component really renders. Paste the component here and you get clean, indented HTML, plus a short list of what you still need to fill in. It all happens in your browser, so nothing you paste is uploaded.

How to Use It – Step by Step

Five short steps. Paste the examples into the tool above to try them.

Step 1 Paste or Open Your Component

  • Paste it: a whole file with imports and types, one component, or just a piece of JSX.
  • Open a file: click the upload button, or drag a .tsx, .jsx or .js file onto the tool.
  • Click Sample: loads a small task list with a typed props interface, useState, a .map() list, a condition, a style object and an onClick.

The HTML on the right updates a moment after you stop typing.

Try it: a small component

TSX:

export function Hello({ name }: { name: string }) {
  return <p className="greeting">Hi, {name}!</p>;
}

HTML:

<p class="greeting">Hi, {name}!</p>

💡 {name} is a prop, and its value only exists when the app runs. So it stays in the HTML as a visible placeholder, ready for you to replace with real text.

Step 2 Pick Your Options

The strip above the result shapes the HTML. Your choices are remembered in this browser.

  • Component: shows up when the file has more than one. Pick one, or keep All to see each of them with its name in a comment.
  • Expressions: keep {user.name} as a visible placeholder, or remove it.
  • Conditions: for a ? <A /> : <B />, show the first option or both.
  • Indent: 2 or 4 spaces.
  • Fill in components: put the markup of components defined in the same code in place of their tags (more on that below).
  • Comments: keep {/* comments */} as <!-- comments -->.
  • Full HTML page: wraps the result in <!DOCTYPE html>, <head> and <body>.

Step 3 Look at the Preview

Preview, next to HTML Code, shows the result in a safe frame with scripts off. It doesn’t load your stylesheet, so you see the plain structure: headings, lists, buttons and the placeholders.

Step 4 Read the Notes Tab

Notes lists what was changed for you (Done) and what’s worth a look (To do): placeholders to fill in, event handlers that were left out, lists that show one item, and components from other files. The number on the tab is the count of to-dos.

Step 5 Copy or Download

  • Copy: puts the HTML on your clipboard.
  • Download: saves an .html file named after the component.
  • Want to tweak it live? Paste the HTML into the HTML Editor, or check it with the HTML Validator.

What Changes Between TSX and HTML

These are the changes the converter makes. Most of them are React’s JavaScript names going back to the HTML ones.

TSX / JSXHTML
className class
htmlFor for
tabIndex, readOnly, maxLength tabindex, readonly, maxlength
colSpan / rowSpan colspan / rowspan
autoComplete, autoFocus autocomplete, autofocus
srcSet, crossOrigin srcset, crossorigin
defaultValue, defaultChecked value, checked
strokeWidth, fillRule (SVG) stroke-width, fill-rule
xlinkHref (SVG) xlink:href
style={{ marginTop: 8 }} style="margin-top: 8px"
disabled={true} / disabled={false} disabled / (left out)
aria-hidden={true} aria-hidden="true"
<br />, <img /> <br>, <img>
<div /> <div></div>
<>...</> (removed)
onClick, key, ref (left out)

Attributes and Booleans

disabled={false} means “not disabled” in React, so it’s left out. required and disabled={true} become a bare required and disabled. A true or false on an attribute that isn’t on/off, like title={true}, is left out too, as React does. Event handlers are left out and listed in Notes.

TSX:

<label htmlFor="email">Email</label>
<input id="email" type="email" required disabled={false} tabIndex={1} onChange={handleChange} />

HTML:

<label for="email">Email</label><input id="email" type="email" required tabindex="1">

style Objects Become CSS Text

Property names go back to CSS spelling, and plain numbers get px the way React adds it, except on properties that take a bare number, like lineHeight, zIndex, opacity and flex.

TSX:

<div style={{ marginTop: 8, lineHeight: 1.5, backgroundColor: '#f3f4f6' }}>Box</div>

HTML:

<div style="margin-top: 8px; line-height: 1.5; background-color: #f3f4f6">Box</div>

Expressions, Lists and Conditions

The converter doesn’t run your code, so anything that depends on data is shown the most useful way it can be.

A .map() List Shows One Item

React repeats the <li> for every item in the array. Here you get one, with placeholders, which is usually what you want as a template. Copy it as many times as you need.

TSX:

<ul className="list">
  {items.map((item) => (
    <li key={item.id}>{item.label}</li>
  ))}
</ul>

HTML:

<ul class="list">
  <li>{item.label}</li>
</ul>

Conditions Show the “Yes” Side

isLoggedIn && <a> is shown as if the condition were true. For error ? <A /> : <B /> you get the first option, or both when you pick Both under Conditions.

TSX:

<div>
  {isLoggedIn && <a href="/account">My account</a>}
  {error ? <p className="error">{error}</p> : <p>All good</p>}
</div>

HTML (Conditions: Both):

<div>
  <a href="/account">My account</a>
  <!-- if error: -->
  <p class="error">{error}</p>
  <!-- otherwise: -->
  <p>All good</p>
  <!-- end if -->
</div>

Components: Filled In or Marked

<Badge> is defined in the same code, so its markup is filled in with the props passed to it (and its default tone). <Link> comes from another package, so it’s marked with comments around its content.

TSX:

function Badge({ text, tone = 'info' }: BadgeProps) {
  return <span className={`badge badge-${tone}`}>{text}</span>;
}

export default function Header() {
  return (
    <header>
      <h1>Docs</h1>
      <Badge text="Beta" />
      <Link href="/start">Get started</Link>
    </header>
  );
}

HTML (Component: Header):

<header>
  <h1>Docs</h1>
  <span class="badge badge-info">Beta</span><!-- <Link> -->Get started<!-- </Link> -->
</header>

What It Can’t Do

Going the other way? The HTML to JSX converter turns HTML into React markup, and HTML to TSX builds a typed React component from it.

Frequently Asked Questions

What does a TSX to HTML converter do?

It reads a React component written in TSX (or plain JSX) and gives you the markup it returns as plain HTML. className becomes class, htmlFor becomes for, style objects become style="..." text, fragments disappear and every tag is closed the HTML way. The imports, hooks and TypeScript types around the markup are skipped, because HTML has no use for them.

Does it run my React code?

No. It only reads the code, the way an editor does, and it does that in your browser, so nothing you paste is uploaded. That also means it can’t know what’s in your props or state while the app runs. Something like {user.name} is kept as a visible placeholder (or removed, if you pick that), and you fill in the real text yourself.

How are .map() lists and conditions handled?

A list made with items.map(item => <li>...</li>) shows one <li>, with placeholders like {item.label} inside, and the Notes tab reminds you that React repeats it for every item. For cond && <Banner />, the banner is shown as if the condition were true. For a ? <A /> : <B />, you get the first option, or both (marked with comments) when you pick Both under Conditions.

What happens to components like <Button> or <Card>?

When the component is defined in the code you pasted, its markup is filled in, with the props you passed where they’re plain values: <Badge text="New" /> becomes <span class="badge">New</span>. A component from another file (a UI library, say) can’t be filled in, so it’s marked with comments, <!-- <Card> --> and <!-- </Card> -->, around whatever you put inside it. Paste that component’s code too and it gets filled in. Next.js <Link> and <Image> are the exception: they become a plain <a> and <img>.

How is the style object converted?

style={{ marginTop: 8, backgroundColor: 'red' }} becomes style="margin-top: 8px; background-color: red". Property names go back to the CSS spelling, WebkitTransform becomes -webkit-transform, and numbers get px the way React adds it, except on properties that take a plain number, like lineHeight, zIndex, opacity, flex and fontWeight. CSS variables such as '--gap' keep their name.

Where did my onClick go?

Event handlers (onClick, onChange, onSubmit and the rest) are left out. They point at functions in your component, and a plain HTML page doesn’t have those. The Notes tab lists every one, so you can add a small script or an onclick yourself if the page still needs to react to clicks. key and ref are left out too, since they only mean something to React.

Will my CSS or Tailwind classes still work?

The class names are kept exactly, so they work as soon as the page loads the same stylesheet (your CSS file, or Tailwind’s). The Preview here doesn’t have your styles, so it shows the plain structure. Class names built with cn() or clsx() keep their fixed parts, and the conditional ones ({ active: isActive } or isActive && "active") are shown as if they were on, with a note. Styles written in JavaScript, like styled-components, aren’t converted.

Does it work with plain JSX and .jsx files too?

Yes. TSX is JSX with TypeScript types, and the types are simply skipped, so .jsx, .js and .tsx files all work. You can also paste a bare piece of JSX without a component around it, like <div className="box">Hi</div>.

What if my code has a mistake in it?

You still get the HTML for everything that could be read. A yellow bar above the result says which line looks wrong (for example “<div> is never closed”), and the Notes tab lists every problem it found. Fix that line and the HTML updates right away.