JavaScript Formatter

Indent and space JavaScript so it can be read.

Code Formatters Free, no sign-up Runs in your browser

JavaScript Formatter tool

About the JavaScript Formatter

JavaScript Formatter takes code that is minified or inconsistently written and prints it with consistent indentation, spacing around operators and one statement per line. Nesting becomes visible, which is usually all you need to start reading unfamiliar code.

The hard part of formatting JavaScript is knowing what is code and what is not. A brace inside a string is not a block. A slash might start a comment, a division, or a regular expression, and which one it is depends on what came before. Template literals can contain expressions that contain more template literals. The formatter tracks all of this, so strings, comments, regular expressions and template literals pass through byte for byte while the code around them is reshaped.

This is a formatter rather than a parser-based pretty-printer, which means it is fast, it never fails on syntax it does not recognise, and it handles modern code it has never seen. The trade-off is that deliberately unusual formatting is normalised rather than preserved. For a project with its own style rules, a dedicated tool in your build pipeline remains the better choice.

How to use the JavaScript Formatter

  1. Paste your JavaScriptMinified, bundled or hand-written.
  2. Choose an indent sizeTwo spaces, four spaces or a tab.
  3. Press FormatThe indented code appears below.
  4. Copy or downloadTake the formatted file.

Features

  • Consistent indentation for blocks, objects and arrays
  • Spacing around operators, commas and keywords
  • Strings, template literals, comments and regex passed through untouched
  • Handles arrow functions, classes and modern syntax
  • One statement per line
  • Never throws on unfamiliar syntax
  • Copy or download the result

Who uses this tool

The javascript formatter is used by writers, developers, students, marketers and anyone else who needs the job done once without installing software. Common cases include:

  • Reading minified or bundled code
  • Tidying a snippet copied from a forum
  • Making a diff readable before review
  • Finding the structure of unfamiliar code
  • Normalising indentation in a small script

Frequently asked questions

Will formatting change what my code does?

It changes whitespace only, so behaviour is unchanged. The one thing worth checking is automatic semicolon insertion: code that relies on it is fragile already, and reformatting fragile code is a good moment to add the semicolons.

How are strings and regular expressions handled?

They are detected and passed through exactly as written. That matters because a brace or a slash inside a string looks identical to one in code, and a formatter that cannot tell them apart corrupts the file.

Can it reverse minification?

It restores whitespace and structure, not names. A minifier that renamed variables to single letters has thrown that information away, and nothing can bring it back.

Does it handle JSX or TypeScript?

Partly. Ordinary TypeScript annotations format acceptably. JSX contains markup inside expressions and is better handled by a tool that parses it properly.

Should I use this in my build?

No. Use a dedicated formatter in your project, configured once and run automatically. This tool is for the times you are looking at code that is not yours.

Is my code uploaded?

No. Formatting runs in your browser, so proprietary code stays on your device.

If the javascript formatter is not quite what you need, these other free tools solve closely related problems.

JavaScript Minifier

Shrink JavaScript by removing comments and whitespace, without renaming anything.

Code Formatters Use tool

CSS Formatter

Format CSS with consistent indentation, spacing and one declaration per line.

Code Formatters Use tool

HTML Formatter

Pretty-print HTML with consistent indentation, or collapse it back down.

Code Formatters Use tool

JSON Formatter

Pretty-print and validate JSON, with the exact line and column of any error.

Developer Tools Use tool

Live HTML Editor

A three-pane editor with a live preview that updates as you type.

Developer Tools Use tool