Code Beautifier for JavaScript, HTML, CSS and JSON

Minified files, code copied from a browser's developer tools and snippets pasted from chat all lose their indentation, which makes them hard to read and debug.

Paste the code and this beautifier formats it as you type, with consistent indentation and line breaks. It detects whether the code is JavaScript, HTML, CSS or JSON, or you can choose the language yourself, and you can pick 2 spaces, 4 spaces or tabs.

How the formatting works

JavaScript, HTML and CSS are formatted with js-beautify, a long-established open-source formatter. It understands the language, so semicolons and braces inside strings, regular expressions and for-loop headers stay where they belong. JSON is parsed and re-printed, which also checks it: invalid JSON, such as a trailing comma or single quotes, is reported instead of being reformatted.

Readable, not rewritten

Beautifying only changes whitespace: indentation, line breaks and spacing around operators. It does not rename variables or change behaviour, so the formatted code runs exactly as before. Minified code with shortened names stays hard to follow even when formatted; source maps are the way to see the original names.

How to use this tool

  1. Paste your code: In the input box on the left.
  2. Check the language: It is detected automatically; choose it if the guess is wrong.
  3. Pick an indent: 2 spaces, 4 spaces or tabs.
  4. Copy the result: The formatted code appears on the right as you type.

Features

Worked examples

A one-line loop

Input: for(let i=0;i<3;i++){console.log("a;b{c}",i)}

for (let i = 0; i < 3; i++) {
  console.log("a;b{c}", i)
}

Result: Properly indented, with the semicolons and braces inside the string left untouched.

Minified CSS

Input: body{margin:0;color:#333}.btn{padding:8px 16px}

Result: Each rule on its own block, one property per line, ready to edit.

Who it is for

Tips

Frequently asked questions

Will formatting change how my code works?

No. Only whitespace changes; the code does the same thing.

Is my code uploaded?

No. Formatting happens in your browser.

Can it format TypeScript or JSX?

Simple TypeScript and JSX usually format reasonably as JavaScript, but for full support use your editor's formatter, such as Prettier.

Related tools