Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

A free HTML to React (JSX) converter that runs in your browser

I made a small tool: paste HTML, get React JSX or a typed component. It's free, needs no signup, and runs in your browser. The link is at the end. The problem HTML and JSX look alike, but they differ in small

I made a small tool: paste HTML, get React JSX or a typed component. It's free, needs no signup, and runs in your browser. The link is at the end.

The problem

HTML and JSX look alike, but they differ in small, annoying ways. class has to become className, for becomes htmlFor, inline style="..." strings must turn into objects, and void tags like <img> and <input> must be self-closing. When you paste a big chunk of markup from a template, a design export or an old page, fixing all of this by hand is slow and easy to get wrong.

What the converter does

  • Converts attributes to their JSX names (class to className, for to htmlFor)
  • Turns inline style strings into style objects with camelCase properties (background-color becomes backgroundColor)
  • Self-closes void elements
  • Converts hyphenated SVG attributes to camelCase (viewBox, strokeWidth)
  • Can wrap the result in an exported component, with TypeScript typing (React.FC)

Example

Input:

<div class="user-card" style="background-color: #0f172a; padding: 16px;">
  <label for="username">Developer Name</label>
  <input type="text" id="username" name="username" placeholder="Alex" />
  <img src="/avatar.png" alt="Profile avatar">
</div>

Output (TypeScript component mode):

import React from 'react';

export const UserCard: React.FC = () => {
  return (
    <div className="user-card" style={{ backgroundColor: "#0f172a", padding: "16px" }}>
      <label htmlFor="username">Developer Name</label>
      <input type="text" id="username" name="username" placeholder="Alex" />
      <img src="/avatar.png" alt="Profile avatar" />
    </div>
  );
};

What it doesn't do

  • Parsing uses the browser's DOM parser, so <script> tags and inline event handlers like onclick are stripped.
  • Server template syntax (PHP, Blade, Liquid) is not evaluated and stays as plain text.
  • It converts markup only. State, props and event logic are still your job.

Privacy

The conversion happens in your browser. The HTML you paste is not uploaded to a server.

Try it

https://www.devmaple.com/tools/html-to-react

I'm the author, and the site has 38 free browser tools in total: https://www.devmaple.com

If you find a snippet it converts wrongly, I'd like to see it. You can send it through the contact page: https://www.devmaple.com/contact

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.