Menu
PDF Tools
Image Tools
Converters & Utilities
Seller & Print Tools
Accounting & Business
Calculators
Text & Writing Tools
Developer & Web Tools
Creator & Social Tools
Browser Utilities & Games
Document & Design Makers
Text & Developer Tools
Exam & Form Tools

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.

How to use HTML to JSX Converter online

  1. Paste the HTML. A snippet or a section.
  2. Read the JSX. The converted code appears at once.
  3. Wrap the result. Put it in one parent element.
  4. 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?
Because class is a word with a special meaning in JavaScript.
How is style written in JSX?
As an object, with camelCase property names.
Are self-closing tags needed?
Yes, empty tags such as br and img must be closed.
Are data attributes changed?
No. data- and aria- attributes stay the same.
Does it make a component?
No. It converts the markup only.
Is the text I paste into the HTML to JSX Converter uploaded?
Your text stays on this device when you use the HTML to JSX Converter. The editor may keep the last text locally and offers to bring it back; you can dismiss it.
Can I chain the HTML to JSX Converter with another tool?
Yes. Copy the HTML to JSX Converter result, or press Use result as input and carry on with the new text.

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.

More tools in Text & Writing Tools →

Search tools