Conversor de HTML a JSX gratuito
El Conversor de HTML a JSX reescribe HTML plano en JSX válido de React. Renombra atributos (class pasa a className, for pasa a htmlFor), auto-cierra elementos vacíos, convierte cadenas de estilo en línea en objetos de estilo y corrige algunas otras peculiaridades exclusivas de HTML.
The related syntax converters are the HTML to Pug Converter and the CSS to Tailwind Converter, and the attributes it transforms are formatted first by the HTML Formatter & Beautifier. For the data behind a component, the JSON to CSV Converter is the bridge.
Cómo usar HTML a JSX
- 1 Paste your HTML.
- 2 Convert. Attribute names are rewritten for JSX and self-closing tags are normalised.
- 3 Check the reported warnings for attributes with no direct equivalent.
- 4 Copy the JSX into your component.
Cómo usarlo
Pega tu HTML a la izquierda y haz clic en Convertir. La salida JSX aparece a la derecha, lista para soltar en un componente React.
- class pasa a className, for pasa a htmlFor
- Los elementos vacíos se auto-cierran
- Las cadenas de estilo en línea pasan a objetos de estilo
- Convierte atributos HTML a sus equivalentes JSX
- Se ejecuta enteramente en tu navegador
¿Por qué convertir HTML a JSX?
JSX parece HTML pero es más estricto. React rechaza palabras reservadas como class y for, exige camelCase para la mayoría de los atributos y necesita etiquetas vacías auto-cerradas. Esta herramienta maneja esas diferencias automáticamente para que puedas pegar marcado existente directamente en un componente.
Preguntas frecuentes
Which attributes get renamed?
The ones that collide with reserved words or differ in JSX. `class` becomes `className`, `for` becomes `htmlFor`, and attributes containing hyphens become camelCase, so `tabindex` becomes `tabIndex`. Event handlers change to camelCase too, and data and aria attributes keep their hyphens as written.
Why does my inline style break?
Because JSX expects a style as an object rather than a string. A `style` attribute written in CSS syntax has to be converted to an object with camelCased properties and quoted string values. The conversion does this, but a value that relied on CSS syntax such as a shorthand with a slash cannot be represented directly.
What about comments and event attributes?
HTML comments become JSX comments, which need braces around them. Inline event attributes such as `onclick` should not be carried across at all — in React those are functions passed as props, not strings, so a converted string handler is a defect rather than a fix.
Herramientas para desarrolladores relacionadas
También te puede interesar
Herramientas de otras categorías que suelen combinarse con HTML a JSX: