JavaScript formatter

Paste compact or untidy JavaScript and get it back with consistent indentation, spacing and line breaks. Choose the indentation, where braces go and whether long lines are wrapped.

  • Free
  • No sign-up
  • Runs in your browser

Runs in your browser — your text is never sent to our servers.

How to use JavaScript Formatter

  1. Paste your code into the Input box, or click Open a file to load a .js or .mjs file.
  2. Choose the Indentation (2 spaces, 4 spaces or Tab) and the Braces style (same line or own line).
  3. Optionally set Wrap long lines to 80 or 120 characters, and tick or untick Keep existing blank lines.
  4. Read the result in the Output box, then click Copy or Download to save formatted.js.

Features

  • Indentation of 2 spaces, 4 spaces or a tab
  • Braces on the same line or on their own line
  • Optional wrapping of long lines at 80 or 120 characters
  • Option to keep or drop existing blank lines
  • Formats whole files or short snippets
  • Runs in your browser, so the code is not uploaded

Supported formats and limits

  • Maximum input: 5,000,000 characters

Examples

InputResult
function greet(name){const msg="Hello, "+name+"!";if(name){console.log(msg)}else{console.log("Hello!")}return msg} greet("OneVixa");function greet(name) { const msg = "Hello, " + name + "!"; if (name) { console.log(msg) } else { console.log("Hello!") } return msg } greet("OneVixa"); — Default settings (2 spaces, braces on the same line).
const a=[1,2,3].map(x=>x*2);if(a.length){run()}else{stop()}const a = [1, 2, 3].map(x => x * 2); if (a.length) { run() } else { stop() } — 4 spaces, Braces set to Own line.

Limitations

  • The tool does not check syntax. Code with errors is formatted as it is and no error is shown.
  • It does not rename variables, remove code or minify. To make a script smaller, use the JavaScript minifier.
  • Semicolons are not added or removed, so code without them stays without them.
  • For JSON data, the JSON formatter is the better tool, because it also validates the text.
  • Input is limited to 5 million characters.

Learn more

JavaScript engines ignore most whitespace, so the same program can be written as a neat, indented file or as one very long line. Humans read the first version far more easily. Indentation shows which statements sit inside a function, an if or a loop, and a line break after each statement makes it possible to follow the logic and to review changes line by line.

Teams usually agree on one style, such as 2 spaces and braces on the same line, and apply it automatically so that a diff shows real changes rather than arguments about spacing. A browser-based formatter is handy for a quick job: reading a minified script you did not write, tidying a snippet before sharing it or checking how a style option looks.

A formatter works on the text and does not understand what the program means. It cannot find a missing bracket, unused variable or logic error, and it will not restore names that a minifier shortened. The MDN JavaScript documentation is a good reference for the language itself.

Frequently asked questions

Does formatting change what my code does?

No. It only changes spaces, tabs and line breaks, which JavaScript ignores between tokens. Strings and comments keep their text.

Will it tell me about syntax errors?

No. It does not parse the code for errors, so broken code comes out formatted as far as possible. Run the code or a linter to find mistakes.

Can I format a minified file?

Yes. Paste the compact code and it is expanded into readable lines. Variable names that a minifier shortened stay short, because the tool cannot recover the original names.

Is my code uploaded?

No. The formatting runs in your browser and nothing is sent to a server.

Sources

Last reviewed: September 30, 2026