JavaScript Beautifier - Format JS Code Online
Make JavaScript readable again
Production bundles, inline scripts and snippets copied out of dev tools tend to arrive as one long line. This beautifier (js-beautify) adds line breaks and indentation so you can follow the control flow. Paste code on the left and the formatted version appears on the right.
Options
- Indent: two spaces, four spaces or tabs.
- Braces: same line, same line but keep one-liners, own line (Allman), end expand, or keep as written.
- Keep blank lines: keep blank lines from the input, collapsing runs of them to one.
- End with newline: add a trailing newline, so Git does not report "No newline at end of file".
Quotes, semicolons, comments and names are never touched. If the indentation looks wrong towards the end of the output, the snippet is probably missing a closing brace or bracket. Multi-megabyte bundles can take a second or two, since the work happens on your machine.
Example
Input:
function total(items){let sum=0;for(const i of items){if(i.qty>0){sum+=i.price*i.qty}}return sum} Output (2 spaces, same-line braces):
function total(items) {
let sum = 0;
for (const i of items) {
if (i.qty > 0) {
sum += i.price * i.qty
}
}
return sum
} Reading minified code
Beautifying a minified file gives you its structure back, but not its names. function(t,n) stays
function(t, n) because the minifier threw the real names away. If the site ships a source map (look for a
//# sourceMappingURL= comment at the end of the file), the browser's dev tools can show the original source,
which beats anything a beautifier can do. Without one, search the formatted output for string literals such as API paths
or error messages. They survive minification and are the quickest way to find the code you care about.
When to use something else
For your own project, run Prettier in your editor or as a pre-commit hook so every file stays consistent. This page is for one-off jobs: a script embedded in someone else's HTML, a tag manager snippet, or a bundle you want to read without opening an IDE.
Related tools
Going the other way? The JavaScript minifier shrinks code with Terser and shows the gzip size. To turn markup into React code, use HTML to JSX.
Related Tools
Epoch / Unix Timestamp Converter
Convert between Unix epoch timestamps and human-readable dates.
Regex Tester
Test regular expressions against text with match highlighting.
UUID Generator
Generate random v4 UUIDs for use in databases and APIs.
Colour Converter
Convert colours between HEX, RGB, and HSL formats.