Minify or Beautify JavaScript
FormatEverything runs locally in your browser — nothing is uploaded
Two directions in one tool. Minify strips comments and redundant whitespace down to as few lines as possible; beautify re-lays out code that was squeezed onto one line, using braces and semicolons as the structure. Both are pure text transformations with no parsing — which is why minifying never renames a variable or removes dead code (that is a bundler or obfuscator job), and also why it can never break your code: strings and template literals are carried through verbatim, and nothing but whitespace is ever changed. Minifying has one easily-missed rule: removing a line comment must keep its newline — `return // note` followed by `a` means `return;` plus a statement (undefined) under automatic semicolon insertion, and deleting the newline turns it into `return a`, which returns a value instead. The same limitation as beautifying applies: brackets inside regular expression literals are read as structure.
Features
- The output is syntax-highlighted, with keywords, strings and comments colour-coded
- 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
- Known limitation: without lexical analysis, brackets inside regular expression literals are read as structure
- Minify mode: strips comments, line breaks and indentation down to as few lines as possible
- Minifying keeps /*! and //! licence comments — stripping someone’s copyright notice is a legal risk
- Minifying never fuses two tokens: return a, a + +b and 1 .toString() all stay parseable
- Removing a line comment keeps its newline, so a return statement cannot silently change meaning
- No variable renaming and no dead-code elimination (that is an obfuscator’s job)
How to use
- Paste your JavaScript into the input box
- Choose Minify to squeeze it onto few lines, or Format to lay it out
- In format mode you can also pick the indentation width
- Click Copy, or Download to save it as a .js file
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.
- Does minifying change how the code behaves?
- No. Minifying only removes comments and whitespace and does not touch a single character of code — semicolons, brackets, operators and string contents all stay as they are. It does keep the newline that ends a line comment: with `return // note` followed by `a`, that newline carries meaning in JavaScript (automatic semicolon insertion), and removing it turns the line into `return a`, changing a function from returning undefined to returning a value. The minified output is safe to run as-is.
- Can I use minifying as obfuscation?
- No, and please do not. It does not rename variables, remove dead code or rewrite control flow — variable names come out exactly as they went in, just without the whitespace and comments around them. Real obfuscation needs a parser and an understanding of scope, and the result is something you can no longer debug. Use it to make a file smaller, nothing more.
- 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
JS Obfuscate
FormatStrip comments and whitespace, escape strings and numbers, rename local variables — smaller, and harder to skim. All local.
CSS Formatter
FormatFormat CSS online: one declaration per line, selectors split at commas. Minify only strips structural whitespace, keeping meaningful spaces in values.
JSON Formatter
FormatFormat, validate and minify JSON in a collapsible tree with syntax highlighting and line numbers. Search, edit, delete or convert to Python dicts.
JSON to Code
FormatTurn JSON into TypeScript interfaces, Go structs, Java classes or Rust structs, with missing keys marked optional. Runs locally in your browser.
SQL Formatter
FormatFormat SQL online: one clause per line, consistent keyword case, subqueries indented deeper. Minify strips comments and extra whitespace, all locally.
JSON5 Converter
FormatParse JSON5 into strict JSON: comments, unquoted keys, single quotes, trailing commas, hex and Infinity all work, with errors located by line.