Skip to content
ToolZone

Beautify HTML/CSS/JS

Format and beautify HTML, CSS, or JavaScript code, adding consistent indentation and line breaks to make minified or messy code readable again.

Runs in your browser. Nothing you enter or upload leaves your device.

Beautified output…

Keyboard shortcuts

Run the main action
⌘ / Ctrl + Enter
Copy the result
⌘ / Ctrl + Shift + Enter
Download the result
⌘ / Ctrl + S
Paste a file or image into file tools
⌘ / Ctrl + V
Search all tools
⌘ / Ctrl + K
Show these shortcuts
?

You can also drop files anywhere on the page.

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. 1

    Click JavaScript, HTML or CSS to choose the language (JavaScript is selected by default).

  2. 2

    Paste your code into the input box.

  3. 3

    Read the formatted result in the output panel below.

  4. 4

    Click the copy button to copy the beautified code.

Worked examples

Minified CSS

You copied a compressed rule set from a stylesheet.

Input
.btn{color:#fff;padding:8px 16px;}a:hover{color:red}
Result
.btn { color:#fff; padding:8px 16px; } a:hover { color:red }

Each rule gets its own block and each declaration its own indented line.

One-line JavaScript function

A short function written without line breaks.

Input
function add(a,b){var c=a+b;return c;}
Result
function add(a,b){var c=a+b; return c; }

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.

Input
<nav><ul></ul></nav>
Result
<nav> <ul> </ul> </nav>

Each tag gets its own line, and the list is indented inside the nav element.

Limitations
HTML mode does not know about void elements, so tags like <img> and <br> increase the indent of the lines after them, and elements with text content are not indented as parents. JavaScript mode only adds line breaks after semicolons, so code with braces but few semicolons stays mostly on one line, and semicolons inside strings or for loops also trigger line breaks. CSS mode removes the space after colons in declarations and puts a semicolon inside a string or URL on a new line.
Assumptions
Input is a short snippet in the selected language. Two spaces is an acceptable indentation width.
Privacy
Formatting happens in your browser and the code you paste is not sent anywhere or stored.

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.

Related tools