Migrating HTML templates to React? Here's what you need to know about converting HTML to React components.
Key Differences: HTML vs JSX
1. class → className
// HTML
<div class="container">
// React JSX
<div className="container">
2. for → htmlFor
// HTML
<label for="email">Email</label>
// React JSX
<label htmlFor="email">Email</label>
3. Inline styles become objects
// HTML
<div style="background-color: red; font-size: 14px;">
// React JSX
<div style={{ backgroundColor: 'red', fontSize: '14px' }}>
4. Self-closing tags
// HTML (optional closing)
<img src="photo.jpg">
<br>
<input type="text">
// React JSX (required self-closing)
<img src="photo.jpg" />
<br />
<input type="text" />
5. Event handlers
// HTML
<button onclick="handleClick()">
// React JSX
<button onClick={handleClick}>
Automated Conversion
For large HTML files, use the free HTML to React Converter to automatically:
- Convert
classtoclassName - Convert
fortohtmlFor - Transform inline styles to React objects
- Fix self-closing tags
- Rename event handlers to camelCase
- Wrap output in a functional component
When to Use
- Migrating legacy HTML templates to React
- Converting HTML from design tools (Figma HTML export)
- Porting server-rendered templates to client-side React
- Converting email templates to React Email components
Related Tools
- HTML to JSX - Convert without component wrapping
- SVG to React - Convert SVG to React components
- CSS to Tailwind - Convert CSS to Tailwind classes
Top comments (0)