Developer 🔒 Runs in your browser — no data sent to servers

Code Formatter & Minifier

Beautify or minify HTML, CSS, JavaScript and SQL, with the language detected for you — all in your browser.

Input
Output

Code Formatter - Beautify or Minify HTML, CSS, JavaScript and SQL

Paste code that arrived on one line, or code that is ready to ship, and turn it into what you need: neatly indented and readable, or minified to the fewest bytes. The formatter handles HTML, CSS, JavaScript and SQL, recognises which one you pasted, and does everything in your browser, so source code, queries with table names and snippets from a client project never leave your device.

Formatting is for people: reviewing a pull request, reading a minified bundle, debugging a query someone wrote as one long line. Minifying is for machines: smaller files load faster and cost less bandwidth. One tool covers both directions.

How to use it

  1. Paste your code. Language is set to Detect automatically; choose HTML, CSS, JavaScript or SQL if the guess is wrong.
  2. Press Format to indent it, or Minify to compress it.
  3. Set Indent to 2 spaces, 4 spaces or tabs, and for SQL pick the SQL dialect and how Keywords are written.
  4. Press Copy or Download. The line under the tool shows the size before and after, and how much minifying saved.

What each language uses

LanguageFormatMinify
HTMLjs-beautify: nested tags indented, inline tags kept on their lineComments and whitespace between block elements removed; pre, textarea, script and style left untouched
CSSjs-beautify: one declaration per lineComments and whitespace removed, strings kept, spaces kept where values need them, such as 0 auto and calc(100% - 32px)
JavaScriptjs-beautify: braces, blocks and chained calls indentedTerser: parses the code, removes dead weight and shortens local variable names
SQLsql-formatter: clauses on their own lines, dialect-awareComments removed and whitespace outside quotes collapsed to single spaces

The three libraries are open source and are loaded only when you first use their language, so the page itself stays light.

Formatting SQL

A long query written on one line is hard to review. The SQL formatter puts SELECT, FROM, WHERE, GROUP BY and each JOIN on their own lines and indents the columns and conditions under them. Dialects matter because databases disagree about syntax: backtick-quoted names are MySQL, square brackets are SQL Server, :: casts are PostgreSQL. Choose the dialect you use from standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, Oracle PL/SQL, BigQuery and Snowflake. Keywords can be written in UPPERCASE, lowercase or As written; the names of your tables and columns are never changed.

Minifying safely

Minified code has to behave exactly like the original, and the safe way to guarantee that is to understand the code rather than delete characters blindly. JavaScript is therefore minified by Terser, which parses it into a syntax tree first; if the code has a syntax error, you get the line and column instead of broken output. The CSS minifier keeps the spaces that carry meaning, and the HTML minifier leaves one space between inline elements such as <span>a</span> <span>b</span>, because removing it would join two words on the page.

Minifying is not a substitute for compression on the server. Gzip or Brotli usually shrinks text files by 70% or more on top of minification, and the two work well together.

Common uses

  • Reading a minified file from a third-party library or a production bundle while debugging.
  • Cleaning up HTML exported by an email builder or a CMS before editing it by hand.
  • Reviewing a query copied from a log, an ORM debug line or a colleague's chat message.
  • Shrinking a snippet of CSS or JavaScript before inlining it into a page or an email template.

Related tools

For JSON, the JSON formatter validates and indents it, and the JSON converter turns it into YAML, CSV or XML. To see exactly what formatting changed, paste the before and after into Text Compare. For a single job, the task pages open this tool ready to go: HTML formatter, SQL formatter, CSS minifier, JavaScript minifier and JavaScript beautifier.