JavaScript Beautifier
Turn minified or messy JavaScript into clean, indented, readable code with 2 spaces, 4 spaces or tabs.
Format, beautify and minify JavaScript online. Turn minified or messy code into clean, readable code with the indentation you like, and check the syntax in one click.
Paste JavaScript, or open a .js file from your computer.
Pick the indentation, or switch to Minify to shrink the file.
Copy the result, or download it as a .js file.
Readable code is easier to understand, debug and maintain, and JavaScript is the language where code most often arrives in a form that is impossible to read: a minified bundle from a production site, a snippet copied from a forum with broken indentation, a file written by a teammate with a different style, or code generated by a tool. Our free JavaScript formatter fixes all of these in a second. Paste your code and the JS beautifier rewrites it with clean indentation, sensible line breaks and consistent spacing, whether you want 2 spaces, 4 spaces or tabs. Need the opposite? Switch to Minify and the JavaScript minifier removes comments and unnecessary whitespace to make the file smaller. After every run, the tool also checks the result for syntax errors using your browser's own JavaScript engine, without ever running your code. It supports modern JavaScript, including ES6 and newer syntax, arrow functions, classes, async and await, template literals, destructuring and regular expressions. Everything works in your browser, so your source code stays private, and the tool needs no signup.
Searching for a JS formatter, a JavaScript prettifier, a JS unminifier or a JavaScript minifier online? This page covers all of them in one place. Switch between Beautify and Minify with one click, use the output as the next input, and check the syntax of your code without running it. The tool works on Windows, Mac, Linux, Android and iPhone, and needs no extension, no Node.js and no account.
Turn minified or messy JavaScript into clean, indented, readable code with 2 spaces, 4 spaces or tabs.
Remove comments and extra whitespace safely, keep license comments, and see how many bytes you save.
Your code is checked in your own browser and is never uploaded or executed, so it stays private.
You can format a script in a few seconds, and the result updates while you work.
A JavaScript beautifier, also known as a JS formatter, a JavaScript pretty printer or a code prettifier, is a tool that rewrites the layout of your code without changing its behavior. JavaScript ignores most whitespace, which means that the same program can be written on a single line or spread over a thousand lines, and it will work exactly the same. A beautifier uses that freedom to put each statement on its own line, indent nested blocks, add spaces around operators and align braces, so that the structure of the program is visible at a glance. Teams use formatters to keep a consistent style across a codebase, and developers use online beautifiers to read code that they did not write, such as a third-party script or a minified library.
This is what a minified snippet looks like before it is formatted.
function add(a,b){if(a>b){return a-b}else{return a+b}}const user={name:"Sara",roles:["admin","editor"]};
And this is the same code after using the JavaScript beautifier with 2 spaces.
function add(a, b) {
if (a > b) {
return a - b
} else {
return a + b
}
}
const user = { name: "Sara", roles: ["admin", "editor"] };
When you open a production website's script, you will often see one very long line of code. This is minified JavaScript: the whitespace and comments have been removed, and in most cases the variable and function names have been shortened to single letters to reduce the file size and speed up loading. To read it, paste the code into the formatter and choose Beautify. The structure comes back, with indentation and line breaks, and you can follow the logic, set breakpoints and debug. It is important to know that formatting cannot restore the original names or comments that a minifier deleted. If you have the original source or a source map, use that for the best results. A formatter is still the quickest way to make minified code readable.
Minifying JavaScript reduces the file size, which means faster downloads and better page speed, a factor that affects both user experience and search performance. This tool performs a conservative minification: it removes comments, line breaks and unnecessary spaces, keeps the line breaks that JavaScript needs for automatic semicolon insertion, and can keep license comments that start with /*! so that you stay compliant with open-source licenses. It does not shorten variable names or restructure the code, so the result is predictable and easy to debug, but the savings are smaller than those of full minifiers such as Terser or esbuild. For a production website, the best practice is to run a build tool that bundles, minifies and compresses your assets, and to serve them with gzip or Brotli. Use this tool for quick jobs, small scripts, snippets and bookmarklets.
The formatter understands modern JavaScript syntax, including let and const, arrow functions, classes with static and private members, async and await, generators, template literals with nested expressions, optional chaining, nullish coalescing, spread and rest, destructuring, regular expression literals, numeric separators and BigInt. It formats code by reading it token by token, rather than building a full syntax tree, which is how many online beautifiers work. This keeps it fast and means it never rewrites your tokens, but it also means that unusual code may not be laid out exactly as an editor plugin would do it. JSX and TypeScript are not supported. If the code has a syntax error, the tool still formats it as well as it can and shows you the error from the syntax check. Always test your code after formatting.
The two modes have their own settings. The table below shows what each one does.
| Setting | Mode | What it does | Best used for |
|---|---|---|---|
| Beautify | Mode | Rewrites code with indentation, line breaks and spacing. | Reading minified code, debugging and code review. |
| Minify | Mode | Removes comments and extra whitespace to make the file smaller. | Preparing a script for production. |
| Indentation | Beautify | Choose 2 spaces, 4 spaces or tabs. | Matching the style of your team or project. |
| Keep blank lines | Beautify | Preserves empty lines between code blocks. | Code that already groups logic with blank lines. |
| Keep license comments | Minify | Keeps /*! ... */ comments in the minified file. | Libraries and open-source code that need their license text. |
| Use output as input | Both | Moves the result back into the input box. | Beautify first, then minify, or the other way round. |
| Question | Beautify | Minify |
|---|---|---|
| Main goal | Make code easy to read | Make the file small |
| File size | Usually larger | Smaller |
| Who reads it | Developers | Browsers |
| When to use it | Development, review and debugging | Before publishing a website or app |
| Is it reversible? | Yes, you can always minify again | Only partly. Layout can come back, original names and comments cannot |
A good workflow is simple: edit and review the beautified source, then minify a copy for production. Keep the readable file as your master version.
| Problem | Likely cause | How to fix it |
|---|---|---|
| Syntax check shows an error | A missing bracket, quote or comma in the code. | Go to the line and column shown, fix the problem and format again. |
| Output looks unchanged | The code was already formatted. | Try another indentation size or switch to Minify. |
| Names are single letters | The code was minified before it reached you. | Formatting restores layout, not original names. Use the source or a source map. |
| Comments are missing after Minify | Minify removes comments by design. | Turn on Keep license comments for the ones you must keep. |
| Blank lines disappeared | Keep blank lines was off. | Turn it on in Beautify mode. |
| A very large file feels slow | Everything runs in your browser. | Format one file at a time, or split the script. |
The JavaScript formatter runs in your web browser, so you can beautify and minify JS code online on Android, iPhone, Windows, Mac and Linux. Whether you search for a JS beautifier for Chrome, a JavaScript minifier for Mac or a fast way to read minified code on your phone, the steps are the same: open the page, paste your code, pick a mode and copy the result.
Your code stays in your browser. The tool checks the syntax with your own browser engine and never runs your script, so nothing is uploaded or executed. As a general habit with any online tool, remove API keys, passwords and tokens from code before you paste it.
Formatting is often one step in a bigger workflow. These related free tools help with the rest of the job:
Our free JavaScript formatter helps you read, clean up and shrink your code in seconds. Paste a script, choose Beautify or Minify, and copy the result, with no signup and without your code ever leaving your browser.
Quick answers about formatting, beautifying and minifying JavaScript.
A JavaScript formatter, also called a JS beautifier, takes messy, compressed or badly indented JavaScript and rewrites it with consistent indentation, line breaks and spacing so that it is easy to read. It does not change what the code does, only how it looks.
Paste your code into the input box, or open a .js file, choose Beautify, and pick the indentation you prefer. The formatted code appears instantly and you can copy it or download it as a .js file. Everything runs in your browser, so your code is never uploaded.
Yes. Switch to Minify to remove comments and unnecessary whitespace and shrink the file. This is a safe whitespace-and-comment minifier. It does not rename variables or rewrite the code like a full build tool does, so the size savings are smaller but the code stays predictable. Use a bundler such as esbuild or Terser for production builds.
It should not. The formatter only changes whitespace and line breaks, it never edits the tokens of your code. After formatting, the tool also runs a syntax check in your browser's own JavaScript engine, without running your code, and tells you if it finds an error. As with any tool, review the result before you deploy it.
Yes. Arrow functions, classes, async/await, template literals, optional chaining, spread, destructuring, generators and regular expressions are supported. JSX and TypeScript are not supported, and code that is not valid JavaScript may not format perfectly.
Yes. Paste a minified file and choose Beautify to get readable code again. Keep in mind that minifiers also shorten variable names, and a formatter cannot bring the original names back, so the code will be readable in layout but not in naming.
The tool is free, with no signup. Your code is processed only in your browser, so it is not sent to a server or stored, and it is never executed.
Format JavaScript, beautify JS code, minify JavaScript or format and validate JSON in seconds. Explore free developer tools to format, convert and debug your code in one place.
Explore All Developer Tools →