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
- Paste your code: In the input box on the left.
- Check the language: It is detected automatically; choose it if the guess is wrong.
- Pick an indent: 2 spaces, 4 spaces or tabs.
- Copy the result: The formatted code appears on the right as you type.
Features
- JavaScript, HTML, CSS and JSON
- Automatic language detection
- 2 spaces, 4 spaces or tabs
- Invalid JSON reported
- Formats as you type; runs in your browser
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
- Web developers: Read minified scripts and styles while debugging.
- Students: Tidy code before submitting assignments.
- Reviewers: Make pasted snippets readable before reviewing them.
Tips
- Choose the language manually for short snippets that could be read either way.
- Use the JSON Formatter for very large JSON files and validation details.
- Keep your project's formatter, such as Prettier, as the final word for committed code.
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.