RevealTheme logo

JavaScript Formatter

Format minified JavaScript with indentation and line breaks at semicolons and braces.

How to use this tool

  1. 1

    Paste or type your JavaScript into the input textarea.

  2. 2

    Watch the indented version appear live in the output box below as you type — there is no Format button.

  3. 3

    Select the formatted text in the output box and copy it with your keyboard (there is no copy button).

  4. 4

    Scan the result for any line that split inside a string, regex, or comment, and fix those by hand if needed.

How does this JavaScript formatter actually work?

This is a lightweight re-indenter, not a real parser. It walks your code one character at a time and applies a few fixed rules: it adds a newline and increases indentation after every opening brace or bracket, decreases indentation before a closing one, breaks the line after every semicolon, and breaks after a comma only when the previous character was a closing brace or bracket (the gap between object or array elements). Indentation is hard-coded to two spaces and cannot be changed, and braces and square brackets are treated identically. Because it has no tokenizer, it cannot tell code from text. Any brace, bracket, semicolon, or comma that lives inside a string, template literal, regular expression, or comment is treated as structural, so a line like const s = 'a;b' will wrongly split at the semicolon inside the string. It also only breaks at literal semicolons, so it does not honor automatic semicolon insertion: semicolon-free code stays on one line. Treat it as a quick visual aid for eyeballing minified or one-line snippets, not as a correctness-preserving tool. For real reformatting that understands syntax, keeps comments, and never corrupts strings, use Prettier or your editor's built-in formatter.

Common use cases

  • Eyeballing a minified vendor bundle or one-line snippet to see its rough structure before debugging.

  • Quickly indenting a short config or object literal you pasted from a chat message or log line.

  • Spreading a dense JSON-like object across multiple lines so nesting becomes visible.

  • Teaching or demoing how braces and semicolons map to indentation levels for beginners.

  • Making a compressed third-party script readable enough to locate a specific function or variable.

  • Sanity-checking that brackets are balanced, since unbalanced input leaves the indentation visibly skewed.

Frequently asked questions

Is this as good as Prettier?
No. This is a quick visual fix that applies a handful of indentation rules character by character. Prettier is a parser-based formatter that understands JavaScript syntax, preserves comments, respects automatic semicolon insertion, and never breaks strings. Use Prettier or your editor's formatter for anything you intend to keep.
Why did my code break inside a string or comment?
The formatter has no tokenizer, so it cannot distinguish code from text. A semicolon, comma, brace, or bracket inside a string, template literal, regex, or comment is treated as structure. For example, const s = 'a;b' splits at the semicolon inside the quotes. Fix those lines by hand or use a real formatter.
Can I change the indentation size or style?
No. Indentation is hard-coded to two spaces and is not configurable. Braces and square brackets are also indented identically, so there are no per-language or per-style options.
Will it add missing semicolons or fix my syntax?
No. It does not validate, parse, or repair anything. It only breaks lines at semicolons that already exist, so semicolon-free code stays on one line, and any syntax errors pass through unchanged.
Why didn't a list like [1, 2, 3] break onto separate lines?
Comma breaks only fire when the character right before the comma is a closing brace or bracket — the boundary between nested objects or arrays. Commas between plain values like numbers or strings are left in place on the same line.
Does this upload my code anywhere?
No. Formatting runs entirely in your browser using local JavaScript. Your code is never sent to a server, so you can safely paste private or proprietary snippets.

Related tools