Skip to main content
Programming Language Tools

Code Beautifier

A multi-language code beautifier - choose JavaScript, CSS, HTML, JSON or C-style code (PHP, Java, C#) and get consistently indented output.

Choose the language and indentation, paste your code, and get consistently formatted output - JavaScript, CSS and HTML use the js-beautify library, JSON a real parser.

JavaScript, CSS and HTML are formatted with the js-beautify library and JSON with a real JSON parser. PHP, Java and C-family code is re-indented by brace nesting - it does not check syntax. For Python and SQL, use the Python Formatter and SQL Formatter.

For a page dedicated to just one language with more detailed guidance, see that language's own formatter in this category.

What Does This Tool Do?

It re-formats code so it is readable again: consistent indentation, one statement per line and tidy spacing. Choose the language first - JavaScript (including TypeScript syntax), CSS and SCSS, and HTML are formatted with the widely used js-beautify library; JSON is parsed and pretty-printed; PHP, Java, C, C++ and C# are re-indented by brace nesting.

Why Use This Tool?

Code copied from a minified file, a chat message, a ticket or an AI assistant often loses its layout. One page for several languages is convenient when you switch between front-end and back-end code in the same session.

How to Use It

  1. Choose the language and the indentation you want (2 spaces, 4 spaces or tabs).
  2. Paste your code.
  3. Click Beautify and copy the result.

Limitations

Formatting never fixes syntax errors, and invalid JSON is reported instead of formatted. The brace-based mode for PHP and C-family languages changes indentation and line breaks only - it does not rewrite spacing inside a line. Python and SQL have their own dedicated formatters.

Example

Minified JavaScript such as:

function total(items){let sum=0;for(const i of items){sum+=i.price*i.qty}return sum}

comes back as:

function total(items) {
    let sum = 0;
    for (const i of items) {
        sum += i.price * i.qty
    }
    return sum
}

When a Beautifier Helps

  • Reading a minified third-party script to find out what it does.
  • Reviewing code pasted into a ticket, chat or email, where indentation was lost.
  • Tidying a snippet before adding it to documentation or a blog post.
  • Making SQL from logs or ORMs readable while debugging slow queries.

Beautifier vs Your Project's Formatter

For code in a repository, use the formatter your team has configured - Prettier, PHP-CS-Fixer or Pint, Black or Ruff - so everyone's editor produces identical output and diffs stay clean. A browser beautifier is best for quick, one-off reading and sharing.

Each language also has its own page: JavaScript, PHP, Python, JSON and SQL. To go the other way, use the Code Minifier.

Frequently Asked Questions

JavaScript, PHP, Python, JSON and SQL. Choose the language so the right formatting rules are applied.

A beautifier adds indentation and line breaks for readability; a minifier removes them to make files smaller.

No. It reformats code but does not repair invalid code, and badly broken input may not format as expected.
Share this tool: