Answer: a code beautifier (also called a formatter or pretty-printer) reformats minified source so humans can read it — one statement per line, consistent indentation — without changing what the code does. Paste minified JS, CSS or HTML below, pick your indent and brace style, and the js-beautify engine (the same library behind editor plugins for 15+ years) reformats it instantly in your browser. A 110-character one-liner becomes 10 readable lines in one click, and your code never leaves the page.

Beautify Your Code

chars (0 = off)
Advertisement

js-beautify Options Reference

OptionDefaultWhat it controls
indent_size4Spaces per indent level (this page defaults to 2, the modern convention)
indent_charspaceCharacter used for indentation — space or tab
preserve_newlinestrueKeep line breaks that already exist in the input
max_preserve_newlinesunlimitedCap on consecutive blank lines kept in one chunk
brace_style"collapse"Brace placement: collapse (K&R), expand (Allman), end-expand, none
space_after_anon_functionfalsefunction () vs function() in anonymous functions
space_before_conditionaltrueif (x) vs if(x)
wrap_line_lengthunlimitedWrap lines at the next opportunity after N characters
end_with_newlinefalseAdd a trailing newline to the output
unescape_stringsfalseDecode \xNN escapes into readable characters

Defaults are documented in the js-beautify 1.15.4 source that this page runs. The tool exposes the five options that matter day to day; the rest are engine defaults.

Worked Examples (Run Through This Tool)

ModeInputOutputGrowth
JavaScript1 line, 110 chars10 lines, 149 chars+35%
CSS1 line, 135 chars17 lines, 182 chars+35%
HTML1 line, 130 chars18 lines, 177 chars+36%

Real minified bundles grow far more — the minifier of a 500 KB library squeezed out every space, so beautified output typically lands 20–40% larger by characters and many hundreds of lines longer.

How the Code Beautifier Works

Minifiers and bundlers make code small; this tool makes it readable again. It runs js-beautify 1.15.4 (MIT license, the library that powers formatter plugins across many editors), loaded from jsDelivr and executed entirely in your browser. Three modes share one page: a JavaScript beautifier, a CSS beautifier, and an HTML beautifier that also reformats the script and style blocks it finds inside your markup.

Beautify vs minify vs format-on-save

Beautifying restores whitespace only. It can't bring back the variable names a minifier shortened or the comments it deleted, so treat it as a reading aid for third-party code, not a round trip. For your own code, a formatter in your editor (Prettier, or js-beautify via a plugin) works from the original source, so nothing is lost. This page fills the gap when all you have is the minified artifact: a production bundle you're debugging, a copied snippet, a theme file shipped compressed.

How to use it

Pick the tab matching your code, paste, and hit Beautify — output appears in the right pane and updates as you type. Choose 2 or 4 spaces (or tabs) for indentation, a brace style for JavaScript, and an optional wrap length that breaks long lines at the next sensible point. Copy grabs the formatted result; Load sample drops in a known minified snippet so you can see the effect before pasting your own.

A worked example

Feed it the one-line JavaScript function add(a,b){return a+b}const calc={add:function(x,y){return x+y;},mul:(a,b)=>a*b};console.log(add(2,3)); — 110 characters, no whitespace. Out comes 10 lines and 149 characters: the function body drops to its own line, the object literal breaks one property per line, and each gains a two-space indent. The logic is untouched; only the layout changed. The CSS and HTML samples behave the same way — a 135-character stylesheet becomes 17 lines with each declaration on its own row, and a squashed HTML document gets its head, body, and nested lists indented back into shape.

Frequently Asked Questions

What does a code beautifier do?

It reformats source code for humans without changing what it does. Minified files strip out every space and newline the compiler doesn't need; a beautifier puts them back — one statement per line, consistent indentation, braces on predictable lines. The code is byte-for-byte different but semantically identical, which is why you can beautify a library file to read it, then keep using the minified original.

Is beautifying the same as minifying in reverse?

Almost, but not exactly. Minification also renames variables, drops comments, and removes dead code — none of which can be recovered from the output. A beautifier restores whitespace and line structure only. Variable names like a, b, and t stay short, and comments stay gone. For code you own, run a formatter in your editor instead so names and comments survive.

Does this tool change or upload my code?

Your code never leaves the browser. The formatting engine, js-beautify, is loaded from a CDN and executed locally — there is no server-side call with your input. The output is deterministic: the same input and options always produce the same output, so it's safe for proprietary code.

Why does the beautified output keep some things on one line?

That's the preserve-newlines behavior and the brace style at work. By default js-beautify keeps blank lines you already have (up to the max you set) and collapses braces onto the statement line, which is the common K&R layout. Switch brace style to expand for Allman braces on their own lines, or set a wrap line length to break long chained calls.

Which brace style should I pick?

Collapse is the default and matches most style guides: if (x) { on one line. Expand puts every brace on its own line (Allman style), end-expand only moves closing braces, and none leaves braces where they found them. If your team has a lint rule, match it here; otherwise collapse with 2-space indent is the most common modern choice.

Can I beautify HTML with embedded CSS and JavaScript?

Yes. The HTML mode of js-beautify recognizes style and script tags and reformats their contents with the matching engine. Just paste the whole document and let it sort out which parts are markup, which are styles, and which are scripts.

Advertisement