JavaScript Formatter & Beautifier
A JavaScript formatter (beautifier) transforms minified or messy JS code into readable, properly indented source. Formatting rules: opening brace stays on the same line, each statement gets its own line, consistent indentation (2 or 4 spaces), preserved strings and comments. Minification reverses this: removes whitespace, comments, and unnecessary characters. function f(){return 1} formats to function f() {\n return 1;\n}.
Format and beautify minified or messy JavaScript code. Choose 2-space, 4-space, or tab indentation. Also minifies JS by removing whitespace and comments. Preserves strings, template literals, and regular expressions. Shows input/output size comparison and line count. Side-by-side input/output view.
Presets
Mode
Input
Output
JavaScript Formatting Rules Reference
| Rule | Minified | Formatted |
|---|---|---|
| Opening brace | if(x){ | if (x) { |
| Statements | a=1;b=2; | a = 1;\nb = 2; |
| Function | function f(){...} | function f() {\n ...\n} |
| Arrow | (a,b)=>a+b | (a, b) => a + b |
| Comments | (removed) | // preserved |
| Strings | Preserved exactly | Preserved exactly |
How to Use
- 1
Paste your JavaScript
Paste minified, messy, or unformatted JavaScript in the input panel. Or click a preset (Minified, Arrow Functions, Async/Await, Class) to load sample code.
- 2
Choose format or minify mode
Select Format/Beautify to expand and indent, or Minify to compress. For formatting, pick your indent style: 2 spaces, 4 spaces, or tab.
- 3
Click Format or Minify
The formatted or minified JavaScript appears in the output panel. Statistics show input/output size and line count.
- 4
Copy the result
Click Copy to copy the output to your clipboard. Paste into your code editor or build pipeline.
Frequently Asked Questions
- What is a JavaScript formatter?
- A JavaScript formatter (also called a beautifier or prettifier) transforms minified, compressed, or messy JavaScript code into readable, properly indented source code. It adds line breaks after statements, indents blocks inside braces and parentheses, and normalizes spacing. Common formatters include Prettier, ESLint --fix, and js-beautify.
- What is the difference between formatting and minifying JavaScript?
- Formatting expands code with whitespace and line breaks for readability. Minifying does the opposite — removes whitespace, comments, and shortens variable names to reduce file size. Formatted code is for development; minified code is for production. A 100-line formatted file might minify to a single line that is 40-60% smaller.
- Does formatting JavaScript change how the code works?
- No. Formatting only changes whitespace, indentation, and line breaks — it never modifies the logic, variable names, or behavior of your code. The formatted and minified versions are functionally identical. JavaScript engines ignore whitespace outside of strings and template literals.
- What indent size should I use for JavaScript?
- 2 spaces is the most common in the JavaScript ecosystem (used by Google, Airbnb, React, Vue, and most npm packages). 4 spaces is common in enterprise codebases and PHP-adjacent projects. Tabs are preferred by some developers for accessibility (configurable display width). Pick one and be consistent across your project.
- How do I format JavaScript automatically in my editor?
- VS Code: Install the Prettier extension, then press Shift+Alt+F (Windows) or Shift+Option+F (Mac). Add "editor.formatOnSave": true to settings for automatic formatting. For CLI: run npx prettier --write "**/*.js". For ESLint: use eslint --fix. Most modern editors support format-on-save with Prettier.
- Does this formatter handle TypeScript and JSX?
- This formatter handles standard JavaScript syntax including ES6+ features (arrow functions, template literals, destructuring, async/await, classes). For TypeScript-specific syntax (type annotations, interfaces, generics) or JSX, use a dedicated TypeScript/JSX formatter or Prettier with the appropriate parser.