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.
| Setting | Lines | Characters |
|---|---|---|
| 2 spaces, statements split | 12 | 221 |
| 4 spaces, statements split | 12 | 237 |
| 2 spaces, statements kept together | 11 | 221 |
| Three statements on three lines, no semicolons | 3 | 42 |
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.
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.