JSX Minifier - Minify React JSX Code

Loading JSX Minifier...

How to Minify JSX/React Code - Step by Step Guide

Step 1

Input Your JSX/React Code

Let's get your JSX code into the minifier! Whether you're optimizing React components for production, reducing bundle size, or preparing code for deployment, you have several convenient options:

•
Paste directly: Copy your React component or JSX code and paste it into the input editor
•
Upload a file: Click "Upload" to select a .jsx, .js or .txt file from your computer (TypeScript files belong in the TSX Minifier)
•
Try the sample: Click "Sample" to load example React code and see how the minifier reduces file size

Example: Unminified JSX Input

Here's what typical, readable JSX code looks like:

import React, { useState } from 'react';

// User card component
const UserCard = ({ user }) => {
  return (
    <div className="card">
      <h2>{user.name}</h2>
      <p>{user.email}</p>
    </div>
  );
};
Step 2

Automatic Minification

A moment after you stop typing, the code is parsed with Babel's JSX parser and printed back in compact form. Nothing is rewritten by search-and-replace, which is how hand-rolled minifiers end up cutting "https://" strings in half:

•
Removes comments: Both // and /* */ comments go, except license banners (/*! ... */, @license, @preserve), JSX pragma comments and /// <reference> lines
•
Drops whitespace: Indentation, line breaks and spaces around operators and brackets disappear. Strings, template literals, regexes and numbers are never touched
•
Keeps JSX text the same: Spaces in text are only removed where they touch a line break, which is what React does anyway, so the rendered page doesn't change
•
Reports problems: Broken code gets the line, column and a pointer to the spot instead of an output that no longer runs

Example: Minified Output

The same code after minifying. It is a short component with one comment, so it shrinks by about a third:

import React,{useState}from'react';const UserCard=({user})=>{return<div className="card"><h2>{user.name}</h2><p>{user.email}</p></div>;};
Original
207 bytes
Minified
137 bytes
Step 3

Download or Copy Result

The badge next to "Minified Output" and the panel under it show the size before and after. From there:

•
Copy to clipboard: Copies exactly what you see in the output editor
•
Download as file: Saves the same text as minified.jsx
•
Check the sizes: Original size, minified size, bytes saved and the percentage, measured in UTF-8 bytes

Example: Real-World Component Minification

A complete React component with hooks and comments:

import React, { useState, useEffect } from 'react';

// Product card component
const ProductCard = ({ product }) => {
  const [quantity, setQuantity] = useState(1);

  useEffect(() => {
    console.log('Product viewed:', product.id);
  }, [product.id]);

  return (
    <div className="product-card">
      <img src={product.image} alt={product.name} />
      <h3>{product.name}</h3>
      <p className="price">${product.price}</p>
      <button onClick={() => setQuantity(quantity + 1)}>
        Add to Cart ({quantity})
      </button>
    </div>
  );
};

After minifying. Note that the text "Add to Cart ({quantity})" keeps its space, because React would show it:

import React,{useState,useEffect}from'react';const ProductCard=({product})=>{const[quantity,setQuantity]=useState(1);useEffect(()=>{console.log('Product viewed:',product.id);},[product.id]);return<div className="product-card"><img src={product.image}alt={product.name}/><h3>{product.name}</h3><p className="price">${product.price}</p><button onClick={()=>setQuantity(quantity+1)}>Add to Cart ({quantity})</button></div>;};
Original
556 bytes
Minified
422 bytes
Saved
134 bytes
Reduction
-24.1%

Frequently Asked Questions

Why would I minify JSX by hand?

Usually to see how much of a component is comments and indentation, to paste a compact snippet into a CodePen, a bug report or a chat message with a length limit, or to inline a small widget into a page that has no build step. If your project already runs Vite, webpack, Next.js or Create React App, the production build minifies for you and does a lot more, so use this page for one-off jobs.

Will the minified JSX still work?

It should behave the same. The code is parsed with Babel's JSX parser first and printed back from that, so line breaks never get glued into a different statement, and strings, template literals, regexes and numbers are written exactly as you typed them (a long ID like 8901240544102066246 or a price like 14.50 keeps every digit). If the parser can't read your code, you get the line and column of the problem instead of a half-minified file.

What gets removed, and what stays?

Comments, indentation, line breaks and spaces around operators and brackets go. Whitespace inside JSX text is trimmed the way React reads it anyway: only where it touches a line break, so <p>Total: {count}</p> still shows Total: with its space. A few comments stay on purpose: /*! license banners, @license and @preserve, @jsx pragma comments (Preact and Emotion rely on them) and /// <reference> lines. Variable and function names are never shortened.

Can I paste TypeScript (TSX) here?

No, this page reads plain JavaScript with JSX, the kind that lives in .jsx and .js files. If you paste code with type annotations, interfaces or generics, it tells you so and points you to the TSX Minifier, which parses TypeScript.

How much smaller will my code get?

That depends on how much of the file is comments and formatting. The sample component on this page goes from 833 to 483 bytes, about 42% smaller. A tightly written component with few comments shrinks far less, because names are kept as they are. The badge above the output shows the exact figure for your code, and the panel under it lists the size before and after.

Is my code uploaded anywhere?

No. Parsing and minifying both happen in your browser, and nothing you paste or upload is sent to our server.