JavaScript Indentation Beautifier
FormattingEverything runs locally in your browser — nothing is uploaded
Re-lay out JavaScript that was squeezed onto one line, using braces and semicolons as the structure: blocks indent a level each, statements get their own line, } else { stays joined, and short object literals stay inline. This tool only re-indents, it does not parse the language, so brackets inside regular expression literals and expressions inside template strings do not take part in the structural scan and results can be off in those cases. String and comment contents are carried through verbatim, and nothing but whitespace is ever changed.
Features
- Indents by brace depth, with the closing brace returned to the matching level
- Breaks lines after semicolons, but not inside for (;;) where they are separators
- Keeps } else {, } catch { and } finally { on one line
- Object literals stay on a single line when they have no semicolon and are short, while code blocks are expanded
- Class bodies are always expanded across lines
- Strings, template literals (including nested templates and ${} expressions) and comments are preserved verbatim
- A line comment always forces a line break, so following code can never be commented out
- Whitespace is only added where the grammar leaves no doubt: after commas and between control keywords and their parenthesis
- Whitespace around operators is left as written, and no semicolon is ever inserted or removed
- Known limitation: without lexical analysis, brackets inside regular expression literals are read as structure
How to use
- Paste your JavaScript into the input box
- Pick the indentation width
- Press Ctrl/⌘ + Enter or click Run
- Click Copy to take the result
FAQ
- Why do regular expressions throw the layout off?
- Telling a division slash from the start of a regular expression needs a full lexer, including unary versus binary operators. Guessing wrong swallows the rest of the line as a pattern, so instead of guessing the limitation is stated plainly: indentation may be off when a regular expression contains brackets.
- Why is the spacing around operators left alone?
- Spacing a=b out requires knowing whether a minus is unary or binary, as in a - -b, i++ or x=-1. That is lexical analysis again, and guessing wrong can change what the code means. This tool sticks to indentation so it cannot break your code by guessing.
- Can it change how my code behaves?
- Nothing but whitespace is touched: no semicolon, bracket, operator or string content is altered. You can verify this yourself by stripping all whitespace from the input and the output and comparing the two.
- Is my code uploaded anywhere?
- No. Everything runs in your browser memory, the page makes no network requests, and it works offline.
Related tools
CSS Formatter
FormattingFormat CSS online: one declaration per line, selectors split at commas. Minify only strips structural whitespace, keeping meaningful spaces in values.
JSON Formatter
FormattingFormat, minify and validate JSON, pinpointing syntax errors to an exact line and column. Optional key sorting; runs in your browser.
JSON to Code
FormattingTurn JSON into TypeScript interfaces, Go structs, Java classes or Rust structs, with missing keys marked optional. Runs locally in your browser.
SQL Formatter
FormattingFormat SQL online: one clause per line, consistent keyword case, subqueries indented deeper. Minify strips comments and extra whitespace, all locally.
XML Formatter
FormattingFormat XML online by tag level, with comments, CDATA and DOCTYPE on their own lines and attribute values left untouched. Runs locally in your browser.
HTML Formatter
FormattingFormat HTML online by tag level, keeping text and inline tags on one line and script or pre content untouched. Runs locally, with nothing uploaded.