This converter turns HTML into a ready-to-use, typed function component. It does everything the
HTML to JSX Converter does (className, style objects, closed tags) and then adds the
TypeScript part: typed event handlers, optional useState and useRef with the right types, a Props type, and it
checks every attribute against React’s own TypeScript types so the file compiles. It runs in your browser, so
nothing you paste is uploaded.
Five short steps. Paste the examples into the tool above to try them.
Step 1 Paste or Open Your HTML
- Paste it: a snippet, a block from a UI kit, or a whole page.
- Open a file: click the upload button, or drag an .html or .svg file onto the tool.
- Click Sample: loads a newsletter card with a form, three event handlers (onsubmit, onchange and
onclick), a select, a checkbox and a CSS variable in a style.
The TSX on the right updates a moment after you stop typing.
Try it: a button with an onclick (Name set to “save button”)
HTML:
<button class="btn" onclick="save()">Save</button>
TSX:
import type { MouseEventHandler } from 'react';
export default function SaveButton() {
const handleClick: MouseEventHandler<HTMLButtonElement> = () => {
// was: save()
};
return (
<button className="btn" onClick={handleClick}>Save</button>
);
}
Step 2 Name It and Pick Your Options
The strip above the result shapes the code. Your choices are remembered in this browser.
- Name: the component’s name, turned into PascalCase (“pricing card” becomes
PricingCard). Leave it empty and it’s taken from the page title or first heading.
- Form fields:
defaultValue (fields start with the HTML’s value and the browser
keeps track of typing) or useState (every field gets typed state and an onChange).
- Refs for ids: a typed
useRef for every element that has an id. - Style constants: inline styles move into typed
CSSProperties constants above the component. - children prop: adds a typed
children prop, and Props as picks type or interface for it. - Indent, Comments, Self-close and Body only (for a whole page) work like on the HTML to JSX page.
Step 3 Read the Notes Tab
Notes, next to Code, lists what was changed for you (Done) and what you still need to look at
(To do): handlers to fill in, attributes that were left out because React’s types don’t accept them, scripts
that were dropped. The number on the tab is the count of to-dos, or of notes when there’s nothing to do.
Step 4 Fill In the Event Handlers
Each handler is an empty, typed function with the old code in a comment. Write (event) when you
need the event, and TypeScript already knows what it is.
The handler from Step 1, filled in by you
const handleClick: MouseEventHandler<HTMLButtonElement> = (event) => {
event.currentTarget.disabled = true; // event is typed for you
save();
};
Step 5 Copy or Download
- Copy: puts the TSX on your clipboard.
- Download: saves it as
YourName.tsx, ready to drop into your components folder. - Messy HTML? Tidy it first with the HTML Formatter or check it
with the HTML Validator.
- Going the other way? The TSX to HTML Converter turns a component
back into plain HTML.
Only types it can be sure of. Here’s each one with a small example, all real output from the tool.
1. Event Handlers: the Right Type for Each Event and Element
onclick on a button and onchange on an input need different types, and the element
matters too. The converter looks both up in React’s own types. If you’d rather type the parameter, the
“event” column is what (event: …) would be.
| HTML | Handler type | event |
onclick on <button> | MouseEventHandler<HTMLButtonElement> | MouseEvent<HTMLButtonElement> |
onchange on <input> | ChangeEventHandler<HTMLInputElement> | ChangeEvent<HTMLInputElement> |
onchange on <select> | ChangeEventHandler<HTMLSelectElement> | ChangeEvent<HTMLSelectElement> |
oninput on <input> | FormEventHandler<HTMLInputElement> | FormEvent<HTMLInputElement> |
onsubmit on <form> | FormEventHandler<HTMLFormElement> | FormEvent<HTMLFormElement> |
onkeydown on <input> | KeyboardEventHandler<HTMLInputElement> | KeyboardEvent<HTMLInputElement> |
onfocus / onblur on <input> | FocusEventHandler<HTMLInputElement> | FocusEvent<HTMLInputElement> |
onmouseenter on <div> | MouseEventHandler<HTMLDivElement> | MouseEvent<HTMLDivElement> |
onpointerdown on <div> | PointerEventHandler<HTMLDivElement> | PointerEvent<HTMLDivElement> |
onscroll on <div> | UIEventHandler<HTMLDivElement> | UIEvent<HTMLDivElement> |
ondragstart on <li> | DragEventHandler<HTMLLIElement> | DragEvent<HTMLLIElement> |
onwheel on <div> | WheelEventHandler<HTMLDivElement> | WheelEvent<HTMLDivElement> |
onpaste on <textarea> | ClipboardEventHandler<HTMLTextAreaElement> | ClipboardEvent<HTMLTextAreaElement> |
onload on <img> | ReactEventHandler<HTMLImageElement> | SyntheticEvent<HTMLImageElement> |
ontoggle on <details> | ToggleEventHandler<HTMLDetailsElement> | ToggleEvent<HTMLDetailsElement> |
💡 The types are imported by name (import type { MouseEventHandler } from 'react'), so
there’s no React. prefix and no import React, which the modern JSX transform doesn’t need.
2. Form State With useState, and Refs With useRef
Pick useState under Form fields and tick Refs for ids. Text fields get
useState<string>, checkboxes useState<boolean>, radio buttons with the same
name share one value, and a multi-select gets useState<string[]>. The state is named after the
field’s name or id. Refs get the element’s own type, so emailRef.current?.focus() just works.
HTML:
<label for="email">Email</label>
<input type="email" id="email" name="email">
<input type="checkbox" name="subscribe" checked>
TSX (Name: “signup form”):
import { useRef, useState } from 'react';
export default function SignupForm() {
const [email, setEmail] = useState<string>('');
const [subscribe, setSubscribe] = useState<boolean>(true);
const emailRef = useRef<HTMLInputElement>(null);
return (
<>
<label htmlFor="email">Email</label>{' '}
<input
type="email"
id="email"
ref={emailRef}
name="email"
value={email}
onChange={(event) => setEmail(event.target.value)}
/>{' '}
<input
type="checkbox"
name="subscribe"
checked={subscribe}
onChange={(event) => setSubscribe(event.target.checked)}
/>
</>
);
}
3. Style Objects and CSS Variables
Inline styles become style objects, checked against React’s CSS types. A CSS variable like --gap
isn’t a property TypeScript knows, so the object gets as CSSProperties. With
Style constants on, the object moves above the component as a constant:
const rowStyle = { ... } as CSSProperties here, or
const rowStyle: CSSProperties = { ... } when there’s no variable in it.
HTML:
<div class="row" style="display: flex; --gap: 8px">Hi</div>
TSX (the markup part):
<div
className="row"
style={{ display: 'flex', '--gap': '8px' } as CSSProperties}
>
Hi
</div>
4. A Props Type: type or interface
Tick children prop. When the outer element holds only text, the text becomes the
children prop, with the old text as its default, so <Badge /> still shows “New”
and <Badge>Sale</Badge> shows “Sale”. Otherwise {children} is added at
the end of the outer element. Both type and interface work the same here; pick the one
your project uses.
HTML:
<span class="badge">New</span>
Props as interface:
interface BadgeProps {
children?: ReactNode;
}
TSX with Props as type (Name: “badge”):
import type { ReactNode } from 'react';
type BadgeProps = {
children?: ReactNode;
};
export default function Badge({ children = 'New' }: BadgeProps) {
return (
<span className="badge">{children}</span>
);
}
5. Attributes React’s Types Don’t Accept
Old HTML is full of attributes like align, border and bgcolor that React’s
types don’t have on most tags. They’d stop the file from compiling, so they’re left out and listed in Notes with
a hint for the CSS that replaces them. Values that only need a small fix get it instead:
tabindex="0" becomes tabIndex={0}, aria-level="2" becomes
aria-level={2} and type="SUBMIT" becomes "submit".
HTML:
<img src="cat.jpg" alt="A cat" border="0" align="left" tabindex="0">
TSX (border and align listed in Notes):
<img src="cat.jpg" alt="A cat" tabIndex={0} />
What’s the difference between JSX and TSX?
TSX is JSX in a TypeScript file (.tsx instead of .jsx). The markup looks the same, but TypeScript checks it: every prop has to exist on that tag, every value has to have the right type, and event handlers and state need types. That’s why HTML that works fine as JSX can still show red errors in a .tsx file. This converter writes the markup and the types together, so the file compiles straight away.
What types does the converter add?
Only the ones it can be sure of. Event handlers get React’s handler type for that event and element, like MouseEventHandler<HTMLButtonElement> for an onclick on a button or FormEventHandler<HTMLFormElement> for an onsubmit. Refs get the element type, like useRef<HTMLInputElement>(null). Form state gets useState<string> or useState<boolean>. Style objects are typed as CSSProperties, and the children prop as ReactNode. It doesn’t invent props or guess what your data looks like, so text stays plain text.
Why are handlers written as const handleClick: MouseEventHandler<…> = () => {…}?
Typing the constant instead of the parameter keeps the file free of “event is declared but never used” errors, which many TypeScript setups turn on. When you need the event, write (event) => {...} and it’s typed for you: event.currentTarget is the button, and on an input event.currentTarget.value is a string. (Use currentTarget: for most events, event.target is only a plain EventTarget.) The old inline code from the HTML sits in a comment inside, so you can see what it used to do.
Why did some attributes disappear?
Because React’s TypeScript types don’t accept them, and keeping them would break the build. Most are old layout attributes like align="center" on a <div>, bgcolor or border on an <img>, or a value the types don’t allow, like type="weird" on a <button>. Each one is listed in the Notes tab with the reason, so you can move it into CSS. Small fixes are made for you instead: tabindex="2" becomes tabIndex={2}, aria-level="2" becomes aria-level={2}, and type="SUBMIT" becomes "submit".
Why do some style objects end with as CSSProperties?
TypeScript only knows real CSS property names, so a CSS variable like --gap in a style object is an error until you tell it the object is fine. The cast does exactly that: style={{ '--gap': '4px' } as CSSProperties}. It’s also added when a style uses a property React’s CSS types don’t list. A value the types reject is lowercased when that fixes it (position: ABSOLUTE becomes 'absolute'), or left out and listed in Notes.
What is the declare module 'react' block at the top?
It shows up when your HTML uses a tag React’s types don’t know: a custom element like <my-widget> or an old tag like <font> or <marquee>. The block tells TypeScript the tag exists and takes any attributes, so the file compiles. Custom elements work in React 19. Old tags are better replaced with a <span>, a <div> or CSS. If your project already declares the same tag somewhere, delete the block.
Which React and TypeScript setups does the output work with?
It’s written for React 19 with the modern JSX transform ("jsx": "react-jsx"), so there’s no import React line, only an import for the hooks and types the file uses. We type-check the output with strict mode, noUnusedLocals, noUnusedParameters and verbatimModuleSyntax, against React 19’s types. React 18 works too, except for the few newer things its types don’t know yet, like the popover and inert attributes and ontoggle on most tags.
Should I pick defaultValue or useState for form fields?
defaultValue gives each field a starting value and lets the browser keep track of what people type, which is enough when you read the form on submit. useState makes every field controlled: a typed useState hook, value={email} and an onChange that updates it, so your component always knows the current value. Checkboxes get useState<boolean>, radio buttons with the same name share one string, and a multi-select gets useState<string[]>.
Is my HTML sent anywhere?
No. The conversion runs in your browser, and nothing you paste is uploaded or saved. Your option choices (component name, form fields and so on) are remembered in this browser only.