ToolsHub4u

Indent minified JavaScript for reading

Paste JavaScript to indent blocks, expand object literals and break long method chains. Line breaks that carry an automatic semicolon are kept.

  • Strings preserved
  • Template literals
  • Runs locally
Ready Developer & Utility
1Enter
2Adjust
3Copy result

JavaScript Beautifier

1

JavaScript input

No data yet Live
2

Beautified JavaScript

Formatted 2 input lines into 11 lines.

Beautified JavaScript

  • Strings and templates were kept wholeQuotes, template literals and regular expressions are copied without reformatting their contents.
  • Layout onlyThe tool adds whitespace and line breaks. It does not parse the program, rename variables or check the syntax.
Input lines
2
Output lines
11
Tokens
64
Characters
217

A beautifier cannot prove that JavaScript is valid. If the file was minified with a name-mangling step, the variables are still short. Run the code or a linter after formatting, and keep the original file.

This page adds line breaks and indentation to JavaScript so it can be read. Paste a minified bundle or a dense function, choose two spaces, four spaces or a tab, and the formatted code appears beside the form. A checkbox controls whether statements separated by semicolons are put on their own lines.

It is a layout tool with a safety net. It tokenises the source far enough to know where braces, brackets, strings and comments begin and end, writes the tokens back with whitespace, and then asks the browser's own JavaScript engine whether the result still parses. It does not build an abstract syntax tree or rename anything.

What it changes and what it keeps

Braces open a new indented block and closing braces return to the previous level. Operators and commas get spaces around them where that is conventional. Strings, template literals and regular expressions are copied as whole tokens, so a brace inside a string is text rather than a block, and a // inside a URL is not a comment. Every character that is not whitespace between tokens is preserved.

Comments are kept where they were. A line comment that followed code on the same source line stays beside that statement, which now reads const a = 1; // trailing. A block comment keeps its own line. The tool does not remove comments, reorder declarations, rename variables or change quote style.

Object literals are now expanded one property per line, because a long run of properties is the hardest thing to read in minified code. Arrays stay on one line so short lookup tables and argument lists do not spread over half a screen. A named import or a destructuring pattern is kept inline: import { readFile } from "node:fs/promises"; stays on one line rather than becoming a three-line block.

Statements, automatic semicolons and indentation

With Put each statement on its own line ticked, a semicolon followed by more code becomes a line break. That is what separates a minified file into readable statements. With the option clear, statements stay on the same line and only blocks are broken, which is useful when a file uses a style where several short statements share a line.

A source line break is now kept when it separates two statements. Minified code usually has semicolons everywhere, but hand-written code often does not, and joining const a = 1 and const b = 2 into one line would produce invalid JavaScript. The test input wrote three statements on three lines with no semicolons and came back as three lines, 42 characters, still parseable.

The option adds line breaks; it does not add or remove semicolons. Code that relied on automatic semicolon insertion is written back exactly as it was, so a missing semicolon remains missing. A line that begins with ( or [ still continues the previous expression, and the formatter does not warn you about that because it is a property of the source.

The indent control changes only leading whitespace. Two spaces is the common JavaScript default, four spaces makes nesting more obvious, and a tab is compact but renders at different widths in different editors. The choice does not change how the code runs.

Objects, chains and braces

A brace is treated as a block or as an object literal depending on what comes before it. After a closing parenthesis, else, try, do or an arrow it opens a block. After =, (, ,, return or : it opens an object. That distinction is what lets an object's properties break onto separate lines while an if body and a class body still indent normally.

A method chain is broken only when it needs to be. When the current line is already longer than 80 characters and the next token is a dot at the top level, the chain continues one level in on the next line. A 153-character chain was split over two lines, 156 characters with the indent; a 79-character chain stayed on one line because it already fitted.

Unary and binary operators are kept apart. -1 stays -1, x - -2 keeps its meaning, and i++ is written without a space. A ternary gets spaces around its colon, so ok ? "yes" : "no" does not run the two halves together.

A worked example

A 74-token sample with an array, a function, a reduce call, an if/else and an object argument was pasted as two lines. With two-space indentation and statement splitting on, the result was 12 lines and 221 characters.

Formatting results for four settings
SettingLinesCharacters
2 spaces, statements split12221
4 spaces, statements split12237
2 spaces, statements kept together11221
Three statements on three lines, no semicolons342

The first run is the expected shape: the array on its own line, the function signature opening a block, the return indented inside it, and the if and else blocks separated. The object passed to console.log now takes three lines with one property each, which is the change most people notice first.

Four spaces produced the same 12 lines and 16 more characters, because deeper indentation adds bytes without adding structure. Keeping statements together produced 11 lines rather than 12, because the trailing semicolons no longer force a break. Line count and size are different measures, and neither one tells you whether the code is correct.

Check the diff, not just the lookFormatting changes whitespace on almost every line. Compare the original and formatted versions with Ignore all whitespace on in the code diff checker if you need to confirm that nothing else moved.

The syntax check

After formatting, the page compiles the output with the browser's JavaScript engine. Compiling reads the whole program and runs none of it, so a snippet with a side effect does not execute. If the code parses, the checklist says so. If it does not, the engine's message is shown, such as Unexpected token ';' for const x = ;.

The check parses a script, not a module. A file using import, export or a top-level await is valid in a module but is reported as unsupported here, so the checklist labels that case Module syntax cannot be checked here instead of calling it an error. The layout is still produced either way.

A passing check means the punctuation is still balanced and the keywords are in a legal order. It does not mean the program is correct. A formatter cannot know whether a variable is defined, whether a promise is awaited or whether the logic does what the author intended.

When to use a real parser

Use this page to read code, inspect a snippet from a stack trace, or prepare a file for review. Use a parser-based formatter such as Prettier when the output must follow a project style exactly, because those tools understand the grammar and can make consistent decisions about line width, trailing commas and parentheses.

Very large files are processed in the tab. There is no server round trip and no stated line limit, so the practical ceiling is the browser's memory and patience. A multi-megabyte bundle may take a moment and produce a page that is slow to scroll.

The reverse operation is the JavaScript minifier. To check that formatting changed only whitespace, paste both versions into the code diff checker with Ignore all whitespace on. For JSON rather than JavaScript, the JSON formatter is stricter and will reject invalid input.

Questions

Common questions

Short answers about this tool and its limits.

Does it keep code that relies on automatic semicolons?

Yes. When the source puts two statements on separate lines without a semicolon between them, the output keeps the break instead of joining them. Three statements written on three lines came back as three lines and still parsed.

Does it check that the code is valid?

It compiles the output with the browser's JavaScript engine and reports the engine's message if it fails, such as Unexpected token ';'. Compiling does not run the code. Module syntax is reported as unchecked rather than as an error.

Does it add missing semicolons?

No. The option only adds line breaks where a semicolon already exists. Formatting never inserts or removes punctuation, so a missing semicolon is still missing after the run.

Why are my object properties on separate lines?

An object literal now puts one property per line, because a long run of properties is the hardest part of minified code to read. Arrays stay inline, and an import or destructuring pattern stays inline too.

Are long method chains broken?

Yes, once the line passes 80 characters. The chain continues on the next line one level in. A chain that already fits stays on one line, so short expressions are not spread out for no reason.

Are comments kept?

Yes. A comment that followed a statement on the same line stays beside it, and a block comment keeps its own line. Comments are never removed or moved to a different statement.

Does it rename or remove anything?

No. Names, quotes, numbers and comments are copied as they are. If the file was minified with a name-mangling step, the short variable names stay short; this page does not reverse that.

Is my code uploaded?

No. Formatting and the syntax check run in the browser with no account or server copy. Copy or download the result before closing the tab, because nothing is stored.