About the Code Beautifier
One place to clean up code from any of the four web languages. The language is detected automatically, or you can choose it, and the code is formatted with your indent settings.
Code copied from a minified bundle, an API response, a Stack Overflow answer or an old project often has inconsistent or missing indentation. Before you can understand or edit it, it needs formatting. This beautifier handles the four core web languages in one place: JavaScript, JSON, HTML and CSS.
Paste code and leave the language on Auto, and the tool detects it from the content; or choose the language yourself if detection guesses wrong. Choose an indent of 2 spaces, 4 spaces or tabs. Formatting is done by js-beautify for JavaScript, HTML and CSS, and by the native JSON parser for JSON, so only whitespace and line breaks change and behaviour stays the same.
Consistent formatting also makes code reviews easier, because reviewers can focus on real changes instead of spacing. If your team uses a formatter such as Prettier, the output here may differ slightly, so run your project’s formatter before committing.
How to use the Code Beautifier
- 1Paste your code.
- 2Pick the language (or leave Auto) and the indent size.
- 3Click Beautify and copy the result.
Key features
- JavaScript, JSON, HTML and CSS.
- Automatic language detection.
- 2, 4 or tab indentation.
- Behaviour-preserving formatting.
- Copy the result in one click.
Practical uses
- Reading minified code from a website.
- Cleaning up snippets before sharing them.
- Formatting JSON from an API alongside other code.
- Tidying code samples for documentation.
Example
A minified function like function a(b){if(b){return b*2}return 0} becomes a properly indented function with the if block and return statements on separate lines.
Tips and common mistakes
- Choose the language manually for short snippets, where detection has little to go on.
- Use dedicated tools such as the SQL Formatter for other languages.
- Beautified code from a bundle still has short variable names; formatting cannot restore originals.
Limitations
- PHP, Python and other languages are not supported.
- Original variable names in minified code cannot be recovered.
Privacy
Code is formatted in your browser.
Frequently asked questions
Which languages are supported?
JavaScript, JSON, HTML and CSS.
Does it support PHP or Python?
Not yet. These languages need different formatters.
Does it change my code’s behaviour?
No. Only whitespace, line breaks and indentation are changed.
Why did it pick the wrong language?
Short or mixed snippets can look like several languages. Select the language yourself to override detection.
Does it remove comments?
No. Comments are kept; only spacing and line breaks are adjusted.
Can it format JSON with comments?
No. JSON with comments is not valid JSON; choose JavaScript to format it as an object literal instead.