Developer tool

JavaScript Formatter and Minifier

Paste JavaScript and select format or minify. Review parser errors before copying.

Runs in your browser. No upload.

Values are processed locally in this browser.

Result

—

About this tool

JavaScript Formatter and Minifier made simple.

This tool never evaluates the source. The formatter is syntax-aware; minified output can be harder to edit, so keep your original file.

Guide

Using JavaScript Formatter and Minifier

The JavaScript Formatter and Minifier takes a piece of JavaScript and either tidies it into a readable layout or squeezes it into a short single line. Formatting uses the Prettier library and minifying uses Terser, both run inside your browser tab. The tool reads your code as text and never runs it. It does not fix bugs, check style rules, bundle files or understand TypeScript.

How to use it

  1. Paste your JavaScript into the source box. It must not be empty and must be under 200,000 characters.
  2. Choose Format to get a clean layout, or Minify to get the shortest version.
  3. Press Calculate. If the code has a syntax error, the box shows the parser's message and a dash instead of a result.
  4. Press Copy result to copy the output. Clear empties the source and sets the action back to Format.

Worked examples

Formatting a one-line script

You enter
Action
format
Source
function add(a,b){return a+b}const x=add(1,2);console.log(x)
You get
Result
function add(a, b) {\n return a + b;\n}\nconst x = add(1, 2);\nconsole.log(x);\n

Each statement goes on its own line, braces get spaces and two-space indents, and semicolons are added where they were missing. Lines are wrapped at 100 characters.

Run through the tool’s own code.

Minifying the same script

You enter
Action
minify
Source
function add(a,b){return a+b}const x=add(1,2);console.log(x)
You get
Result
function add(n,o){return n+o}const x=add(1,2);console.log(x);

Spaces and line breaks go, and the names of the function's own parameters are shortened to single letters. The names add and x stay, because top-level names are kept by default.

Run through the tool’s own code.

Which comments survive minifying

You enter
Action
minify
Source
/*! license */\nfunction greet(name){ /* note */ return "Hi " + name }\ngreet("x")
You get
Result
/*! license */\nfunction greet(e){return"Hi "+e}greet("x");

A comment that starts with an exclamation mark is kept, which is the usual place for a license line. The ordinary note comment is removed.

Run through the tool’s own code.

When it helps

  • Make a minified or one-line snippet readable so you can follow what it does.
  • Tidy code you pasted from several places into one consistent layout before sharing it.
  • Shrink a small script before placing it inside a page, a bookmarklet or a note.
  • Find a missing bracket or stray character, because the parser points to the line and column.

Limits to keep in mind

  • Source text must be non-empty and at most 200,000 characters. The tool works on a single piece of code, with no project files, imports, bundling or source maps.
  • It reads standard JavaScript, and the Format action also reads JSX. TypeScript, such as a type after a colon, is refused with a syntax error.
  • Format always uses the same settings: lines wrap at 100 characters, semicolons are added, and you cannot change quotes, indent size or other style options.
  • Minifying can break code that depends on the names of parameters, on eval, or on reading the source text of a function. Test the output and keep your original file.

Tips

  • Run Format on minified code first if you need to read it, then edit the original source rather than the result.
  • Put licenses and notices in a /*! ... */ comment if they must survive minifying.
  • When you get an error, look at the line and column in the message and check the characters just before that spot.

Sources

Common questions

About JavaScript Formatter and Minifier.

Does this tool run my JavaScript?

No. It parses the text to understand its structure and then prints or compresses it, and it never evaluates the code. A script that would delete files or call a server does nothing here. The result is only text for you to copy.

What is the difference between Format and Minify?

Format spreads the code out for people, with indents and line breaks. Minify removes everything a computer does not need and shortens local names to make the file smaller. Minified code is hard to read, so keep the formatted source.

Why do I see Unexpected token as an error?

The parser found a character where the grammar did not allow one, such as a missing bracket, an extra comma or a type annotation. The message gives the place. Format errors show a line and column. Minify messages can be shorter and less exact.

Can it format TypeScript, JSON, HTML or CSS?

No. This page is set up for JavaScript only. A type annotation such as const x: number = 1 gives an error. The site has separate pages for HTML and CSS, and JSON has its own formatter.

Which comments does the minifier keep?

It keeps some comments, mainly those that start with an exclamation mark, such as /*! license */. Ordinary line and block comments are removed. Check the output if you need a notice to stay in the file.

Is it safe to use the minified code in production?

Often yes, but you should test it. Shortening names or removing code that looks unused can change how a script behaves if it relies on eval or on function names. This tool gives no test and cannot know how your code is used.

Is my code sent to a server?

Your source is processed in the page and is not uploaded. The page does fetch its own formatting code from the site the first time you press Calculate, so it needs a connection then. After that, nothing about your text leaves the tab.

How do I use JavaScript formatter?

Paste JavaScript and select format or minify. Review parser errors before copying.

Is my data uploaded to a server?

No. This tool runs locally in your browser. Your input is not uploaded.