Home › Developer Tools › JavaScript Beautifier

JavaScript Beautifier

Paste minified or messy JavaScript and get clean, consistently indented code, or squeeze it into a compact minified version. Choose your indent, brace style and line wrapping. Your code stays in your browser.

Last updated:

Advertisement
Advertisement

How to use the JavaScript Beautifier

  1. Paste your code into the left box, or press Upload .js to open a file.
  2. Choose the options: indent size, brace style, blank lines and line wrap. Tick JSX for React components.
  3. Press Beautify. The formatted code appears on the right and updates as you edit.
  4. Or press Minify to remove comments and whitespace and see how many bytes you save.
  5. Copy the result or Download it as a .js file.

Brace styles compared

The same function formatted with each brace style:

StyleResultCommon in
Collapse
if (ok) {
    run();
} else {
    stop();
}
Most JavaScript style guides (Airbnb, Google, Standard, Prettier)
Expand
if (ok)
{
    run();
}
else
{
    stop();
}
Teams coming from C# (Allman style)
End-expand
if (ok) {
    run();
}
else {
    stop();
}
Some legacy and PHP-influenced code bases

Collapse, preserve inline behaves like collapse but leaves short blocks such as { x: 1, y: 2 } or if (a) { b(); } on one line when you wrote them that way.

What the minifier removes and what it keeps

  • Removed: line comments, block comments (except /*! license comments if the option is on), indentation, blank lines and spaces that are not needed between tokens.
  • Kept exactly: the contents of strings, template literals (including nested ${…} expressions) and regular expression literals such as /\/\*.*\*\//g.
  • Kept for safety: a line break wherever automatic semicolon insertion could depend on it, for example after return, break, throw and yield, around ++ and --, and between two statements written without semicolons. A space stays between tokens that would otherwise merge, such as a - -b or 1 .toString().
  • Not done: renaming variables, removing dead code or rewriting expressions. Those need a full parser-based minifier such as Terser, esbuild or SWC, which typically save another 20 to 40 percent.

Reading minified code: practical tips

  • Beautify first, then use your browser's search to find string literals such as error messages or URLs, which survive minification unchanged.
  • Single-letter names like e, t and n are usually function parameters renamed by the minifier. Rename them in your copy as you work out what they do.
  • Patterns like !0 and !1 mean true and false, void 0 means undefined, and a && b() is a compact if (a) b().
  • If a //# sourceMappingURL= comment is present, the original sources may be available in the browser developer tools, which is far better than any beautifier.

Which settings match popular style guides?

StyleIndentBracesNotes
Prettier (default)2 spacesCollapseWraps at 80 characters, semicolons on
Airbnb2 spacesCollapseLines up to 100 characters
Google JavaScript Style Guide2 spacesCollapseLines up to 80 characters
StandardJS2 spacesCollapseNo semicolons, space before function parentheses
WordPress and jQueryTabsCollapseSpaces inside parentheses

For a team project, the settings matter less than applying them everywhere. Once you have picked a style, a formatter in your editor or a pre-commit hook keeps every file consistent automatically.

Frequently asked questions

Can it unminify JavaScript?

Yes. Beautifying adds line breaks and indentation back to minified code so you can read it. It cannot restore original variable names or comments that a minifier removed or shortened, but the structure becomes easy to follow.

Does beautifying change how my code runs?

No. The beautifier only changes whitespace and line breaks, which do not affect how JavaScript runs. The one exception is very old code that relies on automatic semicolon insertion in unusual ways, which the beautifier also handles conservatively.

How safe is the minifier?

It removes comments and unnecessary whitespace only. It understands strings, template literals and regular expressions, keeps /*! license comments if you want, and keeps a line break wherever removing it could change automatic semicolon insertion (for example after return). It does not rename variables, so for production builds a full minifier such as Terser or esbuild will save more.

What do the brace styles mean?

Collapse keeps the opening brace on the same line as the statement (K&R style, the most common in JavaScript). Expand puts every brace on its own line (Allman style). End-expand puts only closing braces on their own line, and preserve-inline keeps short one-line blocks such as { a: 1 } on one line.

Can I format JSON or TypeScript here?

JSON is valid JavaScript and formats fine, but the JSON Formatter also validates it. TypeScript usually formats well because the beautifier is tolerant, although type annotations are treated as plain tokens. For JSX, tick the JSX option.

Is my code uploaded anywhere?

No. Formatting and minifying happen in your browser. The js-beautify library is downloaded once from a public CDN, and your code is never sent to a server.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.CSS FormatterBeautify CSS with indent controls and optional property sorting.HTML FormatterBeautify and indent HTML code with a live preview.XML FormatterBeautify, validate and minify XML with a collapsible tree view.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.GraphQL FormatterPretty-print and indent GraphQL queries, mutations and schemas, or minify them, instantly.HTML MinifierMinify HTML: strip comments and whitespace safely and see how many bytes you save.ZIP File CreatorCompress files and folders into a ZIP.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.Gzip Compress / DecompressGzip or deflate text and files, get Base64 output, and decompress Base64 or .gz files.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.TypeScript FormatterFormat TypeScript and TSX code with Prettier: width, tabs, semicolons and quotes options.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.HTML ValidatorCheck HTML for errors and warnings with line numbers, locally or with the W3C Nu checker.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.Strftime Format BuilderBuild Python and C strftime format strings by clicking tokens, with a live preview and reference.
See all 41 Code Formatters & Validators →