JSX Formatter
Format and beautify React JSX code
Input
Formatted Output
Paste your input on the left and the result shows up here.
Or drop a file on this box, , or .
What is JSX Formatter?
A component pulled out of a minified bundle, or out of a chat message that ate the line breaks, arrives as one long line of JSX. This page splits the code into tokens, reads JSX text as text (so the apostrophe in Don't is not a quote), and puts each child element on its own line two spaces deeper than its parent. The plain JavaScript around the markup gets a line break after each statement-ending ; and an indent inside each { } block. Think of it as a quick re-indenter for reading code, not a stand-in for Prettier in your build.
Whitespace in JSX matters more than it looks. Per the React rules, a line break next to text trims the spaces beside it, so <td>Total <b>due</b> today</td> would lose the space before due if the tags were split onto separate lines. Elements whose children mix text and tags are therefore left on one line, exactly as you typed them. A multi-line element after return is wrapped in parentheses instead of being pushed to the next line, where it would make the component return undefined.
The re-indenting is a short script in the page itself, so your component is not posted to a server. It tokenizes the code but does not parse it, which means it never reports a syntax error: broken JSX still comes out re-indented. Open the result in your editor before trusting it.
How to Use the JSX Formatter
There is no Format button to hunt for. The right pane is rebuilt on every edit you make to the left one.
Paste, Upload, or Load Sample
Paste a component into the Input pane; Upload accepts .jsx, .js and .txt files. Pressing Sample gives you a one-line subscriber list with a .map() inside a <ul>. A lone self-closing element like the one below comes out unchanged, because it has no children to indent:
<SubscriberCard subscriberId="SUB-1001" plan="Unlimited 5G" dataUsage={45.2} status="active" carrier="Verizon" /> View Formatted Output
The right panel shows the formatted JSX. For the Sample, the markup after return becomes return (, then <div className="subscribers">, with <h1>Subscribers</h1> and the <ul> one level in, and ); to close. The <li> stays on one line because its text (: and - ) has spaces React renders. Attributes are kept as you wrote them.
Copy or Download
Copy takes the right pane as it stands and Download saves it as formatted.jsx. Only whitespace changes and the parentheses after return, so the result renders the same as what you pasted. The trash icon empties both panes.
When You'd Actually Use This
React Development
Format JSX components to understand the structure, debug issues, or improve readability. Works great with React components or any JSX-based code.
Code Review
A diff that touches a minified JSX line shows a single changed line a thousand characters wide. Paste the old and new versions in turn and you can see which element or prop actually moved before you write the review comment.
Learning JSX
Still getting used to how JSX structures nest? Run a dense component through and follow the indentation. Every child element sits one level under its parent, and a { } expression between tags gets a line of its own, so you can see exactly where markup stops and ordinary JavaScript takes over.
Debugging
Trying to find a bug in your JSX? Formatting reveals the structure, making it easier to spot incorrect nesting or a prop on the wrong element. It does not check syntax, so pair it with the validator for a missing closing tag.
Common Questions
Is my JSX code stored?
No. The page re-indents the code with its own script and makes no request while doing it. A file opened with Upload is read by the browser's FileReader into the left pane, not sent anywhere, and closing the tab throws it away.
What JSX formats are supported?
We support all valid JSX according to React standards. Components, props, nested elements, JavaScript expressions – everything standard JSX supports. See MDN JavaScript docs for more on JavaScript syntax.
Can I format invalid JSX?
We'll try to format it, but if there are syntax errors, the output might not be perfect. Fix errors first for best results. Check React docs for JSX best practices.
What indentation does it use?
Two spaces per level, for tags and for { } blocks alike. Line breaks you already had are kept, and blank lines are squeezed to one.
How big can my file be?
Processing happens in your browser, so it depends on your device. A component file of a few hundred lines is done before you look up. Very large files might take a few seconds, and it reruns on every edit.
Does it work with TypeScript JSX?
Mostly. Type annotations are just tokens to the formatter, so they pass through unchanged. A generic arrow such as <T,>(x: T) => x is recognised as not being a tag because no matching </T> follows.
Other JavaScript Tools You Might Need
This page only re-indents. To catch a real syntax error, shrink code for production or move a component over to TypeScript, try these: