HTML to JSX Converter
This tool converts HTML to JSX for React. It changes class to className, writes style as an object, camel-cases events and closes empty tags.
- Free, no sign-up
- Nothing is sent to a server
- Worldwide
How to use HTML to JSX Converter online
- Paste the HTML. A snippet or a section.
- Read the JSX. The converted code appears at once.
- Wrap the result. Put it in one parent element.
- Copy it. Copy or save the result.
Why use this free HTML to JSX Converter
- class to className
- Style as an object
- Events in camelCase
- Empty tags closed
- Comments converted
- Share by link
Why HTML needs changes
JSX looks like HTML but is JavaScript, and it follows different rules. Some attribute names clash with JavaScript words, so class becomes className and for becomes htmlFor. Every tag must be closed, and the style attribute takes an object, not a string. Pasting HTML into a component without these changes causes errors or warnings.
What the tool changes
It renames attributes such as class, for, tabindex and readonly to their JSX names. It turns style="margin-top: 4px" into style={{ marginTop: '4px' }}. It changes onclick to onClick with an arrow function. It writes void tags such as br and input with a closing slash, turns comments into {/* */} and escapes curly braces in text.
A worked example
The sample div with a class, a style, a label with for, an input and a br becomes: <div className="card" style={{ backgroundColor: 'red', marginTop: '4px' }}>Name{/* note */}. The data- and aria- attributes are kept as they are. Wrap several top-level tags in one element or a fragment, because JSX needs one parent.
What to check
Inline event code is wrapped in a function, but you will usually replace it with a handler from your component. Attributes the tool does not know are kept as written, so check unusual ones. Script and style tags are turned into text in braces, so move such code into your component yourself.
Related tools
The HTML formatter can tidy the input first, and the HTML to text tool gives the words only. This tool changes the text of the markup and does not run it. It does not build components, so you still need to split a long page into parts of your own.
Using the tool
The HTML to JSX Converter works again whenever the text or an option changes. Press Try a sample to see how it behaves.
HTML to JSX Converter: frequently asked questions
Why does class become className?
How is style written in JSX?
Are self-closing tags needed?
Are data attributes changed?
Does it make a component?
Is the text I paste into the HTML to JSX Converter uploaded?
Can I chain the HTML to JSX Converter with another tool?
Related searches for HTML to JSX Converter
- HTML to JSX Converter online
- free HTML to JSX Converter
- HTML to JSX Converter online free
- HTML to JSX Converter for mobile
- HTML to JSX Converter without sign up
- convert html to jsx converter
- html to jsx converter converter
- HTML to JSX Converter – Text & Writing Tools
HTML to JSX Converter is a free online tool on MAITBOX, in the Text & Writing Tools group. It runs in your browser, so what you type is not sent to a server. It works on Android and iPhone, and on Windows, Mac and Linux, with no download and no account.