JavaScript Formatter Online

Beautify or minify JavaScript instantly in your browser.

Indent:
INPUT0 chars
OUTPUT

When a JavaScript formatter is the right tool

Scripts often arrive as one long line, or with mixed indent from several editors. This page is for a first tidy-up or a compact paste: choose Beautify or Minify, pick 2- or 4-space indent in Beautify mode, and watch the output update as you type. Load Sample pastes a short greet-and-users snippet if you want to try that first.

This is not Prettier and not a JavaScript parser. Beautify is most useful on simple statements. It can split parameter lists awkwardly and will mangle many regular expressions. Minify is usually gentler on regexes. For TypeScript, use the TypeScript Formatter.

Use cases

Reading a minified function

Beautify inserts line breaks at braces, brackets, parentheses, commas, and semicolons so a one-line function is easier to scan. Read the result before you copy it back into a file — parameter lists and for loops are often more broken up than a style guide would want.

Compacting a snippet for a fixture

Minify strips comments and most whitespace, while keeping a space between identifiers so return undefined does not become returnundefined. Check the output if the source contained regexes or unusual template literals.

A quick indent pass, not a style engine

There is no option for tabs, semicolons, or quote style, and nothing is semantically rearranged. Use a local formatter when you need a consistent project style.

How formatting works

Empty or whitespace-only input leaves the output empty. Beautify normalizes line endings, then walks the text while tracking strings, backticks, and comments. Minify uses the same tracking to drop comments and extra spaces. You can copy the result when it is present.

Example — a compact function is split at parentheses and braces
function greet(name) { return name; }

function greet(
  name
) {
   return name;
  
}

The body line is indented three spaces when the setting is 2, and a blank indented line can appear before the closing brace. That is typical of this rewriter, not a second indent setting.

Example — a regex is rewritten as if the brackets were code
const re = /[a-z]{2,}/;

const re = /[
  a-z
]{
  2,
  
}/;

If you need to format a file that contains regular expressions, prefer Minify for compactness, or use a parser-based tool for Beautify.

What this tool does not do

It does not parse JavaScript, preserve regex literals during Beautify, or apply a style guide. Nothing is sent to a server. For JSON, use the JSON Formatter. For stylesheets, use the CSS Formatter.

How to use JavaScript Formatter

  1. Paste your JavaScript, or use Load Sample for a short example.
  2. Choose Beautify or Minify. In Beautify mode, pick 2- or 4-space indent.
  3. Copy the result when it looks right, or Clear to start over.

Frequently asked questions

Does this page parse JavaScript?

No. Beautify and Minify are character rewrites. They track quoted strings, template literals, and // or /* */ comments, and they break or squeeze text at { } [ ] ( ) , and ;. There is no parser, no Prettier or esbuild, and no syntax check. Invalid code is still rewritten.

Why do function parameters and for-loop clauses split onto new lines?

Every comma and every opening or closing bracket can start a new indented line. function greet(name) becomes a parameter on its own line, and for (let i = 0, j = 1; …) is split at the comma and the parentheses. After an opening brace the next line is often indented one space farther than the 2- or 4-space setting, because a leftover space is added after the indent.

Will regular expressions survive Beautify?

Often not. A regex is not treated as a literal, so characters such as [ ] { } ( ) and commas inside /[a-z]{2,}/ are rewritten as if they were code. Minify does not break on those characters and usually leaves a regex intact, aside from comments and whitespace outside strings.

What does Minify change?

It strips // and /* */ comments, then removes whitespace except for a single space when two identifier characters would otherwise touch (for example return undefined). Strings and template literals are copied through. Nested backticks inside a template can confuse the string tracker in both modes.

Is my JavaScript sent to a server?

No. Formatting runs in your browser as you type. Closing the tab discards what you pasted. Do not paste scripts that contain secrets if you would not be comfortable with them sitting in memory on this device.

Is there a file size limit?

There is no server-imposed limit, because nothing is uploaded. A few thousand lines is comfortable. A very large file can make the tab feel slow; in that case, format a smaller excerpt or use a local tool.

Related tools and guides

References

  • Tools such as Prettier parse JavaScript and format it as a syntax tree. This page does not, so regex literals and comma lists can be rewritten incorrectly.
  • For TypeScript sources, the TypeScript Formatter page uses the same kind of character rewriter, not a TypeScript parser.