JavaScript Beautifier
Beautify messy or minified JavaScript and JSX into clean, editor-consistent Prettier output — entirely on this device.
This tool formats — it does not lint, type-check, or change how your code runs.
Press ? for shortcuts
Do it offline:$ npx prettier --parser=babel app.js
How to use it
- Paste a script or drop a .js, .jsx, .mjs or .cjs file — a dropped file is read in place, never uploaded; past 2 MB a labelled button runs only on your press.
- Decide whether trailing semicolons stay, choose single or double quotes, then set the print width and tab width to aim for.
- If the parser rejects the source, the exact message, a caret frame and a Jump-to-error link mark the bad token; your bytes stay as pasted.
- Take the output with Copy, save it with Download, or share a permalink that reopens this exact state.
Drop in minified or hand-mangled JavaScript and read back exactly what Prettier would print. The real Prettier engine runs here through its babel parser — which reads plain JS and JSX from one grammar — inside a Web Worker on your own machine, so nothing you paste is uploaded. Semicolons, quote style, print width and tab width all stay yours to set.
How it works
This is Prettier's standalone build wired to the babel parser and the estree printer, pulled in once as its own chunk and run in a Web Worker so even a large file reprints without locking the tab. Because babel does the parsing, one engine covers JavaScript and JSX with no dialect switch.
Only presentation changes: indentation, line wrapping against the print width, spacing, quote style, and whether each statement keeps or loses its trailing semicolon; trailing commas follow Prettier's defaults. Identifiers are never renamed and statements never reordered, while comments and directives such as "use strict" ride through untouched.
Editor plugins, pre-commit hooks and CI checks embed this same core, so one input at a pinned version and option set reduces to a single output everywhere. What you copy here is what your repository's format check already expects, keeping a review about the change, not the whitespace.
Examples
const sum=(a,b)=>{return a+b;};const sum = (a, b) => {
return a + b;
};
A one-line arrow function opens into spaced tokens and a two-space indented body; strip all whitespace and both sides match character for character.
const msg = "hi"; const items = ['a', 'b'];const msg = 'hi'
const items = ['a', 'b']
With semicolons off both trailing semicolons vanish, and single quotes turn the double-quoted "hi" into 'hi'; the already-single array entries stay put.
const App=()=><div className="card"><span>{count}</span></div>;const App = () => (
<div className="card">
<span>{count}</span>
</div>
);
The one-line JSX component is wrapped in parentheses and laid out as a tree, each element indented beneath its parent.
const result = doSomething(alpha, beta, gamma, delta, epsilon, zeta, eta, theta);const result = doSomething(
alpha,
beta,
gamma,
delta,
epsilon,
zeta,
eta,
theta,
);
Held to a 40-column print width the call breaks apart, so all eight arguments land on their own lines with a trailing comma after the last.
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
Beautifying is not linting or type-checking
This page reprints code; it does not grade it. Unused variables and dead branches format without complaint — only a real parse failure stops the run. Turning TypeScript into JavaScript is a separate converter tool's job.
Semicolons and automatic semicolon insertion
Switch semicolons off and every trailing one is dropped. Where a statement starts with a character that could bind to the line above — a leading [ or ( — Prettier prepends a lone guard semicolon so automatic semicolon insertion cannot change the meaning.
JSX is in, TypeScript syntax is out
The babel parser accepts JSX with no extra setting, so React elements reflow like any expression. Type syntax is a different grammar: a fragment such as const total: number comes back as a syntax error, not a silent strip.
Hidden bytes are surfaced, not swallowed
One leading byte-order mark is removed and reported with the note "Leading byte-order mark removed". Any unpaired UTF-16 surrogate is re-encoded as the U+FFFD replacement character and flagged, so the result is always well-formed.
Large files: the Worker, a timer and a 4 MB ceiling
Past 200 KB the status line counts elapsed seconds beside a Cancel control; past 2 MB the reprint waits for an explicit press. The ceiling is 4 MB — beyond it the tool declines and offers the command-line route below.
Common errors
Unexpected token at line 1, column 12.- The object literal opens with { but the source ends before a matching } — so babel names the first token it cannot accept, here the end of input. A truncated copy-paste is the usual culprit.
Unterminated string constant at line 1, column 11.- A string opens with a quote that never closes on its line, and the column points straight at that opening quote. Add the missing closing quote and the statement parses.
Missing semicolon at line 1, column 2.- Two bare identifiers sit side by side with nothing between them, so the parser wants a semicolon before the second begins. This is a genuine parse failure, not a style preference.
FAQ
Does beautifying change how my JavaScript runs?
No. Only spacing, line breaks, quotes and semicolons are rewritten; identifiers, statement order and every value come back the same. Each example here is re-executed against the engine, and example one is checked character-for-character equal to its input once whitespace is dropped.
Can it format JSX and TypeScript?
JSX yes, TypeScript no. The babel parser reads React markup natively, so components reflow like any expression, but a type annotation such as : number is rejected as a parse error. Convert such code with the dedicated TS-to-JS tool first.
Will the output match Prettier in my editor and CI?
It should, byte for byte, provided the Prettier version and options agree. This page runs Prettier's own defaults — width 80, two-space tabs, double quotes, semicolons on — so if results diverge, compare versions first.
Keyboard shortcuts
- ⌘/Ctrl + Enter
- Beautify or re-run — required past 2 MB.
- ⌘/Ctrl + S
- Download the beautified file.
- ⌘/Ctrl + C
- Copy the beautified code while nothing is selected.
- ⌘/Ctrl + Shift + C
- Force-copy the beautified code over a selection.
- t
- Toggle the theme.
- ? or ⌘/Ctrl + /
- Show the shortcut list for this page.
- Esc
- Close the open dialog and keep your input.