About the Beautify HTML/CSS/JS
Beautify HTML/CSS/JS takes code that has been squashed onto one line, or written without consistent spacing, and adds line breaks and two-space indentation. It is a quick way to get a readable view of a snippet copied from a page source, a minified stylesheet or a short script.
How it works
CSS mode is the most thorough. It strips spaces around { } : ; and commas, then puts each opening brace after the selector, each declaration on its own indented line, and each closing brace on its own line. HTML mode removes whitespace between tags, starts a new line before every <, and indents one level after an opening tag that stands alone on its line, stepping back one level at each closing tag.
JavaScript mode is simpler: it breaks the code into a new line after every semicolon, then indents based on how many { and } appear on each line. It does not add line breaks after opening braces, so a function written on one line becomes several lines split at its semicolons. None of the modes change your code's tokens, only the whitespace between them.
How to use
- 1
Click JavaScript, HTML or CSS to choose the language (JavaScript is selected by default).
- 2
Paste your code into the input box.
- 3
Read the formatted result in the output panel below.
- 4
Click the copy button to copy the beautified code.
Worked examples
Minified CSS
You copied a compressed rule set from a stylesheet.
Each rule gets its own block and each declaration its own indented line.
One-line JavaScript function
A short function written without line breaks.
JavaScript mode splits after each semicolon and indents the lines inside the braces. It does not move the first statement off the line with the opening brace.
Nested HTML
A navigation list written on one line.
Each tag gets its own line, and the list is indented inside the nav element.
Frequently asked questions
Can this un-minify code that has already been compressed?+
It can restore line breaks and indentation, which makes compressed CSS especially readable again. It cannot bring back comments or the original variable names, because a minifier throws that information away.
Will beautifying change how my code runs?+
The tool only changes whitespace between pieces of code. In JavaScript and CSS that does not change behavior. In HTML, whitespace between inline elements can affect spacing on the rendered page, so check the result if layout matters.
What indentation does it use?+
Two spaces per level in all three modes. There is no setting for tabs or four spaces.
Can it format JSON?+
JavaScript mode is not designed for JSON and will only split at semicolons. Use a dedicated JSON formatter for that.