Frontend Tools
JavaScript Beautifier (JS Formatter)
Format minified or messy JavaScript with consistent indentation and spacing. Strings, regexes, template literals and comments are kept exactly as written.
How to use JavaScript Beautifier (JS Formatter)
Paste JavaScript into the box and choose 2 spaces, 4 spaces or tabs. The formatted code appears beside it as you type, ready to copy.
- Paste the codePaste minified, one-line or badly indented JavaScript. Code without semicolons is handled.
- Choose the indentPick 2 spaces, 4 spaces or Tab. Every nested block and case body is indented by that amount.
- Copy the resultCopy the formatted code. Its meaning is unchanged, so it runs exactly as before.
A formatting example
if(true){console.log('ok');} becomes three lines: if (true) {, the indented console.log('ok'); and the closing brace. for(let i=0;i<3;i++) is spaced as for (let i = 0; i < 3; i++) and stays on one line, because semicolons inside a for header don't break lines. In the sample code, the string a;b{c} and the regular expression /[;{}]/g keep their semicolons and braces, else and catch follow the closing brace on the same line, case labels are indented inside switch, and a short object such as { name: n, ok: true } stays on one line.
What it supports and what it doesn't
The beautifier tokenises the code first, so it only changes whitespace and line breaks and the program itself stays the same. It copes with modern syntax such as arrow functions, classes, optional chaining, async and await, as well as code written without semicolons. Comments and blank lines between statements are kept. It does not understand JSX or TypeScript type annotations, so compile those first, and it does not wrap long expressions to a set line width the way Prettier does.
Accuracy and data handling
After adding generated code to a project, test it in the target browsers and responsive sizes. The calculation runs in your current browser; the tool code does not send the input to a processing API.
FAQ
Will the formatted code still run?
Yes. Strings, template literals, regular expressions and comments are kept exactly, and only whitespace and line breaks change, so the behaviour is the same.
Why are some objects kept on one line?
Short object literals with no functions inside stay inline, such as { name: n, ok: true }, as long as the line stays within about 90 characters. Longer objects put each property on its own line.
Can it restore code from a minifier?
It restores indentation and line breaks, but names shortened by tools such as Terser stay short, because the original names aren't in the file. A source map is the way to recover those.
More Frontend Tools
Related toolsConvert between px, rem, em, % and pt using your own root and parent font sizes.
Build fluid clamp() font sizes and spacing that scale between two viewport widths.
Score CSS selectors as (A, B, C) and rank them by specificity.
Generate CSS transition code with easing presets, a curve preview and reduced-motion CSS.
Build responsive CSS grid columns with auto-fit, auto-fill or a fixed count, previewed live.
Shrink HTML by removing comments and spare whitespace, with the byte saving shown.