Code Tools

JS Formatter

All tools

Make compressed JavaScript readable enough to trace, with strings and comments left alone.

How it works

Four simple steps

1

Paste the script

Paste bundled or minified JavaScript, or drop a .js file.

2

Read the blocks

Braces open indented blocks and each statement gets its own line.

3

Minify again

Use Minify to strip comments and spacing from the same input.

4

Take the output

Copy it or download it as formatted.js.

JS Formatter

About JS Formatter

A production error points to line 1, column 48210 of a bundled script, and you want to see what the surrounding code is doing. A quick beautify pass breaks that wall of text into blocks you can actually follow, without installing a build tool.

This is a lightweight, heuristic beautifier rather than a full parser like Prettier. It adds a line break and two spaces of indent after every opening brace, puts closing braces on their own lines, and starts a new line after each semicolon. Single-quoted, double-quoted and backtick strings are copied verbatim, as are // and /* */ comments, so URLs and SQL inside strings keep their spacing. It formats live as you type, accepts a dropped .js file, and a Minify button collapses whitespace back down.

Because it reacts to every semicolon, a loop header like for (let i = 0; i < n; i++) gets split across lines, and regular expression literals that contain quote characters can confuse the string detection. It is great for reading code, less so for committing it. To spot what changed between two builds, paste both formatted copies into the Diff Checker. For shipping, use the JavaScript minifier, and for API payloads the JSON Formatter is a better fit because it actually parses the data.

Your script is processed as text by code already loaded in the page. It is never evaluated or executed, and it is not uploaded.

Keyboard shortcut

Ctrl Enter - Run tool
FAQ

Frequently asked questions

See all FAQs

Answers for this tool. For site-wide help, open the FAQ hub.

No. Minifiers rename variables to single letters and that information is gone. The formatter restores layout only; a source map is the only way to recover original names.

For layout, mostly. It only reacts to braces, semicolons, strings and comments, so type annotations and JSX pass through as text. JSX markup will not be indented the way an HTML formatter would do it.

The beautifier starts a new line after every semicolon, including the two inside a for statement header. Join them back by hand if you plan to keep the code.

View more FAQs

Related tools

View all

HTML Formatter

Beautify and indent HTML markup.

Open

CSS Formatter

Format and pretty-print CSS.

Open

JSON Formatter

Beautify and validate JSON.

Open

XML Formatter

Format XML documents.

Open

Explore 321 free tools

Everything you need as a developer, marketer or creator - in one beautiful place.

Browse all tools