Type a tool name, for example "keyword density" or "transcript".
Format and beautify minified or obfuscated JavaScript code instantly in your browser.
This free JavaScript formatter turns minified or messy code into readable, consistently indented code. Paste your script, choose 2 spaces, 4 spaces or tab indentation, and click Format / Beautify. It suits developers who need to read, debug or review compressed JS, and you can copy the result with one click.
JavaScript formatting means changing the layout of code (line breaks, spacing and indentation) without changing what the code does. A formatter puts each statement on its own line and indents the contents of blocks such as functions, loops and conditions, so the structure is visible at a glance.
Formatting is different from rewriting. The names of your variables, the order of your statements and the logic stay the same. Only the whitespace around them changes. That is why teams format code before code review: reviewers see real changes instead of arguments about spacing.
Minifying is the opposite direction. It removes unnecessary whitespace so a file is smaller. Formatting adds whitespace back so people can read it. This page has both a Format / Beautify button and a Minify button, so you can go either way with the same input.
You format JavaScript online by pasting it into the input box, picking an indentation style and running the formatter. Here are the steps for this page:
If you click the format button with an empty box, you see "Paste some JavaScript first." If copying is blocked by your browser, you see "Copy failed." In that case, select the text in the Output panel and copy it by hand.
The example below shows what the formatter does with a compressed snippet. Paste this into the input box:
function greet(name){return 'Hello, '+name+'!';}var result=greet('World');console.log(result);
With 2 Spaces selected, the output puts the function declaration on its own line, moves the return statement onto the next line indented by two spaces, and places the closing brace on a separate line. The var result statement and the console.log call each get their own line below it. The logic is identical, so the script still prints Hello, World! when it runs.
Switch the menu to Tab and format again. The return statement is now indented with a tab character instead of two spaces. Nothing else changes, which makes the menu a quick way to match the style of the project you are working in.
The Output panel is the full formatted script, ready to copy. A good result has one statement per line, nested blocks that step in one level at a time, and closing braces that line up with the statement that opened them.
Two spaces and four spaces are both common in published JavaScript style guides, so neither is wrong. Pick the one your project already uses. Choose Tab if your team's editor settings control the visual width, since each person can then display tabs at the size they prefer.
Minify compacts the whitespace in your input and shows the message "JavaScript minified." It is handy for a quick size reduction of a small snippet, such as a bookmarklet or an inline script. It is not a replacement for the build step of a production site, which should handle shipping scripts.
A formatter is the right tool whenever you have code you must read but did not write in a readable layout. These are the most common situations:
If your file mixes languages, the code beautifier handles HTML, CSS and JavaScript together. For stylesheets alone, use the CSS formatter, and for data payloads the JSON formatter and validator also checks that the structure is valid.
You get the cleanest results when you paste complete, valid scripts and keep one indentation style across a project. These tips cover the most common problems:
Before replacing a file with formatted output, keep a copy of the original. Then compare the two with the code diff tool. After a formatting pass, the differences should be whitespace only. If you see changed words or symbols, stop and investigate.
This usually means the code contains something the formatter treats cautiously, such as a template literal (text inside backticks), a regex literal or markup embedded in the script. From that point, the formatter keeps the remaining text exactly as you pasted it instead of guessing. To fix it, format the code in sections: split the script before the tricky part, format each piece, and join them again. Or move the template into its own variable.
Check that the input box is not empty and that your text is under 500,000 characters. Very large bundles should be split into smaller files before you paste them.
A formatter restores layout, not meaning. If a minifier shortened your names to single letters, they stay that way. You can rename them yourself in your editor once the structure is readable. The reverse process, hiding logic on purpose, is done with the JavaScript obfuscator.
If your source already contains a mix of tab characters and spaces in strings or comments, the formatter leaves the contents of strings alone. Check the indentation menu setting if the lines of code themselves look inconsistent.
This formatter is deliberately conservative. It is built to avoid changing the meaning of your code, so when it cannot be sure how to interpret a piece of syntax, it leaves that text untouched. That is the right trade-off for debugging and reading, but it means the output is not guaranteed to match the style produced by a full project-level formatter with its own rule file.
It also does not check your code for errors, run it, or fix logic problems. If the original script has a syntax error, formatting will not repair it. And because it works on layout only, deobfuscating heavily protected code still requires time and a debugger. Use formatting as the first step so the code is at least readable.
For other formats you work with every day, see the web developer tools collection.
Paste your script into the Input JavaScript box above, pick your indentation and click Format / Beautify. In a few seconds you get readable code you can copy straight into your project.
Your report has been submitted. We will look into this issue.
A VPN changes your network exit. It does not guarantee anonymity.
Themes, plugins, code, video, audio, graphics & more from 90,000+ authors.
Web Development
Design & Media
Unlimited Access
Explore Envato Market