JSX Formatter and Beautifier
WM-74Paste JSX to format it with Prettier. Choose the indent, quote style, semicolons and line width. Errors show the line and column where parsing stopped.
Runs in your browser. Nothing is uploaded.
JSX
Formatted JSX
How to use it
- Paste your JSX or a React component into the input box, or open a .jsx file.
- Pick the indent and line width, and set semicolons and quotes.
- Read the result. It updates as you type.
- Copy the formatted code or download it as a .jsx file.
What it formats
The formatter is Prettier with its Babel parser. It reads modern JavaScript together with JSX, including arrow functions, async code, optional chaining and class fields, and rewrites the layout: indentation, line breaks, quotes, semicolons and how long JSX is wrapped. A multi-line JSX expression gets wrapped in parentheses, and props that do not fit on a line go one per line. Comments are kept.
Quotes and semicolons
Quote style is set in two places because JSX follows different habits from JavaScript. Single quotes changes quotes in JavaScript strings, and Single quotes in JSX attributes changes the quotes around attribute values. Switching semicolons off makes Prettier write the code without them and add a leading semicolon only where the code would otherwise be read wrongly. Line width decides where Prettier wraps.
What it does not do
It changes layout only. It does not run, lint or type check the code, and it does not rename or reorder anything. TypeScript syntax such as type annotations fails here because this uses the plain JavaScript parser, so use the React formatter and its TSX action for TypeScript. If the code is not valid, you get the line and column and no output.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Invalid JSX: Unexpected token at line 1, column 8 | The parser found something that is not valid JavaScript or JSX at that spot. | Check for a missing bracket, tag or comma near the position, or for TypeScript-only syntax. |
Questions people ask
How do I format JSX online?
Paste the JSX and the formatted code appears as you type. Choose the indent, line width, quote style and semicolons in the options, then copy the result or download it as a .jsx file. Everything runs in your browser.
Does it work for React components?
Yes. A component, hook or whole file is plain JavaScript with JSX, which is what the Babel parser reads. Import and export lines, arrow functions and async code all work. Components written in TypeScript need the TSX action on the React formatter.
Why did Prettier wrap my JSX in parentheses?
When JSX spans several lines after a return or an assignment, Prettier wraps it in parentheses so the code reads clearly and a line break cannot trigger automatic semicolon insertion. Short JSX that fits on one line is left without them.
Can I use single quotes in JSX attributes?
Yes. Tick Single quotes in JSX attributes. It is separate from the Single quotes box, which changes JavaScript strings. Many teams use double quotes in JSX and single quotes in code, which is the default here.
Will it change what my code does?
No. Only whitespace, line breaks, quotes and optional semicolons change. Prettier does not rename variables, reorder imports or rewrite logic. It does not run the code either, so it cannot tell you whether it works.
Why do I get an Unexpected token error?
The Babel parser met something it could not read as JavaScript or JSX. Common causes are a missing closing tag or bracket, an unescaped brace in text, or TypeScript syntax. The error gives the line and column where parsing stopped, which can be just after the real mistake.
About this tool
Uses Prettier with its Babel parser, so it reads modern JavaScript and JSX, including optional chaining, class fields and async code. It rewrites layout only: indentation, line breaks, quotes, semicolons and the way long JSX is wrapped. The code is not run, linted or type checked. TypeScript syntax such as type annotations is not accepted here; use the React formatter and its TSX action for that. Invalid code is reported with the line and column where parsing stopped, and nothing is changed. Comments are kept. Prettier decides the final layout, so the same input always gives the same output.