Loading JavaScript Beautifier...
Please wait a moment

How to Beautify JavaScript - Step by Step Guide

Step 1

Input Your JavaScript Code

Let's get your JavaScript code into the beautifier! You have several convenient options:

•
Paste directly: Copy your minified or messy JavaScript code and paste it into the input editor
•
Upload a file: Click "Upload" to select a .js or .txt file from your computer
•
Try the sample: Click "Sample" to load example code and see how the beautifier works

Example: Minified JavaScript Input

Here's what minified, hard-to-read JavaScript looks like:

function calculateTotal(items){let total=0;for(let i=0;i<items.length;i++){total+=items[i].price*items[i].quantity;}return total;}const cart={items:[{name:"Laptop",price:999.99,quantity:1},{name:"Mouse",price:29.99,quantity:2}],discount:0.1};console.log(calculateTotal(cart.items));
Step 2

Automatic Formatting & Beautification

About half a second after you stop typing, the beautifier reads your JavaScript and:

•
Checks the syntax first: If the parser can't read the code, you get the line and column of the problem instead of half-indented output
•
Adds proper indentation: Makes nested functions, loops, and blocks easy to read
•
Leaves your values alone: Strings, numbers and regexes come back exactly as typed, so 14.50 doesn't turn into 14.5

Example: Beautifully Formatted Output

The function from that snippet, as the beautifier lays it out:

function calculateTotal(items) {
  let total = 0;
  for (let i = 0; i < items.length; i++) {
    total += items[i].price * items[i].quantity;
  }
  return total;
}
Step 3

Choose Format Options

There are two views of the same code, and you can flip between them:

•
Beautified (default): Prettier's layout with 2-space indentation and lines wrapped at 80 characters
•
Minify: Click "Minify" to put the code back on as few lines as possible. Comments go, except license banners; names are not shortened
•
Syntax highlighting: The output panel colours keywords, strings and comments in either view
Step 4

Export Your Formatted JavaScript

When the code looks right, take it with you:

•
Copy to clipboard: One-click copying for quick pasting into your code editor or application
•
Download as file: Save as a .js file for later use or sharing with your team
•
Edit and re-run: Change the input and the output is rebuilt about half a second later

Frequently Asked Questions

How do I make minified JavaScript readable again?

Paste the minified code (a bundle from a CDN, a script you pulled from a page, a one-line snippet from a bug report) into the input box. About half a second after you stop typing it comes back with one statement per line, nested blocks indented two spaces and spaces around operators. Short variable names like a or e stay short, though: a beautifier only changes layout, so it can't bring back names the minifier threw away.

Will beautifying change what my code does?

It shouldn't. The code is read with Babel's parser first and laid out with Prettier, so only whitespace, line breaks, semicolons, parentheses and trailing commas change. Strings, numbers and regexes are written back exactly as you typed them, so a long ID like 8901240544102066246, a price like 14.50 or a quoted "00501" keeps every character.

What happens if my code has a syntax error?

Nothing gets beautified. Instead you see the line and column where the parser gave up, with that line shown and a caret under the spot, so you can fix it and try again. The beautifier doesn't guess at or repair broken code. If you pasted JSON, CSS or HTML by mistake, it tells you that instead.

What does the Minify button do?

It squeezes the code in the input box back onto as few lines as possible: comments, indentation and line breaks between tokens go, while strings, template literals, regexes and numbers stay untouched. License comments that start with /*! or contain @license or @preserve are kept. Names are never shortened, so for a production build a real minifier like Terser, or our JavaScript Minifier, will get the file much smaller.

Does it handle modern JavaScript and React code?

Yes. Arrow functions, classes, async/await, optional chaining, template literals, BigInt literals, ES modules and JSX in React components all work. TypeScript isn't supported here, because type annotations aren't JavaScript; strip them first or use a TypeScript-aware tool.

Is my code uploaded anywhere?

No. Beautifying and minifying both run in your browser, and the code you paste or upload never leaves your device. That also means the size you can handle depends on your computer: a few thousand lines are quick, very large bundles take a few seconds.

Need a smaller file for production? Try the JavaScript Minifier. Want Prettier formatting with a Clear button and line counts? The JavaScript Formatter does that.