Skip to content
cliplimeClipLime

Format and beautify JavaScript

Paste JavaScript, even minified code, and get it indented and readable. Layout only, and nothing leaves this tab.

Your text is processed in this tab and never uploaded

Options

Puts each .then() or .map() call on its own line.

Writes function () instead of function().

Leaves React style tags untouched instead of spacing them out.

0 characters, 0 lines Your text stays in this tab.

This changes layout only. It never adds or removes semicolons or renames anything. For plain JavaScript, your code and the result are read as syntax trees and compared, and the first syntax problem is reported. JSX is not checked.

At a glance

What it does
Beautifies JavaScript as you type, including minified code.
Options
2 or 4 spaces or tabs, brace style, wrapping at 80 or 120, blank line handling, method chain breaking and function spacing.
Syntax
Modern JavaScript: classes, async and await, optional chaining, template literals and private fields.
Never changes
Semicolons, names, strings and the order of your code. It changes layout only.
Safety check
Your code and the result are read as syntax trees and compared. If layout would change the meaning, plainer options are used.
Syntax problems
The first one is reported with its line and column. JSX is not checked.
Privacy
Runs in your browser tab. Your code is never uploaded.

How to do it

  1. 1

    Paste your code

    Paste JavaScript into the left box, drop a .js file on it, or press Example. Minified code from a website works too.

  2. 2

    Choose a style

    Pick the indent, where opening braces go, and whether long lines wrap. Turn on Break method chains to put each call on its own line.

  3. 3

    Read the result

    The beautified code updates as you type. Notes under it report a syntax problem, or confirm that only the layout changed.

  4. 4

    Copy or download

    Copy the result or download it as formatted.js.

What formatting does, and what it never does

The formatter re-indents code, puts statements on their own lines, adds spaces around operators and after commas, and places braces where you choose. It reads your code as a stream of tokens and writes it back with new white space.

It does not add or remove semicolons, rename variables, reorder code, or change quotes. A line that had no semicolon still has none after formatting.

The beautifier works on tokens, so on its own it does not check syntax and cannot be sure it kept the meaning. That is why this page also reads your code with a JavaScript parser before and after formatting, and compares the two syntax trees. If they match, you see a note saying only the layout changed. If they do not, the page tries again with the plainest options. If that also differs, it tells you to compare the two before using the result.

The same parser reports the first syntax problem it finds, with its line and column, as a note under the result. The code is still formatted. Run your linter or tests for anything beyond syntax: this does not check logic, types or style rules.

Making minified JavaScript readable

Paste minified code and the formatter spreads it over lines and indents it, so you can follow the structure. Two things stay as they were: the short names a minifier chose (a, b, t), and any comments it removed. Formatting makes minified code readable, not understandable, because the original names are gone.

A source map, if one exists, is a better way to see the original code. This tool does not read source maps.

Style options

  • Opening brace. Same line puts { after the statement. Next line puts it on its own line. The third choice keeps { on the same line but starts else on a new line.
  • Wrap long lines. At 80 or 120 characters, long argument lists and expressions are broken over lines.
  • Break method chains. a.then().map() becomes one call per line.
  • Space after function. Writes function () instead of function() for anonymous functions.
  • Keep blank lines. Keeps up to two blank lines where you had them, or removes them all.

JSX and TypeScript

JSX is not plain JavaScript, and a formatter that does not know it spaces the angle brackets out like comparison operators. Turn on Keep JSX tags as written and the tags are left exactly as you typed them while the code around them is laid out. A note appears when your code looks like it contains JSX and the option is off.

TypeScript is not supported. Type annotations and generics are not part of the syntax this formatter knows, so the result for TypeScript can be wrong.

Questions people ask

Does it check my JavaScript for errors?

It reports the first syntax problem it can find in plain JavaScript, with the line and column, and still formats the code. It does not check logic, types or style rules, so use a linter and your tests for those. JSX and TypeScript are not read by the check.

Will formatting break my code?

Formatting changes only white space, but beautifiers can get this wrong in rare cases, such as code without semicolons that relies on automatic semicolon insertion. So the page compares the syntax tree of your code with the result. If they differ it falls back to plainer options and says so. The comparison is skipped for JSX and for code over 400,000 characters.

Does it work for TypeScript?

No. It is built for JavaScript. Type annotations and generics may be laid out incorrectly.

Can it format JSON?

Valid JSON also looks fine here, but the JSON formatter is better for it: it checks the syntax, keeps numbers exactly and reports the line and column of a mistake.

Why are there spaces inside my JSX tags?

JSX needs the Keep JSX tags as written option. Without it the formatter treats < and > as operators and spaces them out. Turn the option on and the tags are left as you wrote them.

Is my code uploaded?

No. The formatter loads into your browser tab and runs there. Your code is never sent anywhere, which matters for private source and code with keys in it.