Code Formatter & Minifier

Format or minify HTML, CSS, JavaScript, SQL, XML, YAML and GraphQL, and check XML.

Free tools that run in your browser. Nothing you type, open or create is uploaded to NerdBible or anyone else.

Result

Everything runs in your browser. HTML, CSS and JavaScript are formatted with js-beautify (MIT licence), JavaScript is minified with Terser (BSD licence), SQL is formatted with sql-formatter (MIT) and YAML with js-yaml (MIT); the minifiers for HTML, CSS and SQL, the XML formatter and checker and the GraphQL formatter are small scripts on this page. Each library loads only when you first use it.

How to use it

  1. Pick the language tab and paste your code, or open a file.
  2. Press Format for readable, indented code, or Minify for the smallest version. Choose the indent, and for SQL the dialect and keyword case.
  3. For XML, press Validate to check that the document is well formed: every tag closed and nested properly, attributes quoted, entities and namespace prefixes defined. Any problem is shown with its line and column.
  4. Copy the result or download it as a file.

Questions

Is minified code safe to use in production?

JavaScript is minified by Terser, the same engine most build tools use, so it is reliable. The HTML minifier is cautious: it removes comments and spare spaces but keeps the content of pre, textarea, script and style elements as written. Test the page after minifying either way.

Why did my YAML comments disappear?

Formatting YAML means reading it into data and writing it out again, and comments are not part of the data. Keep a copy of the original if the comments matter.

Which SQL dialect should I choose?

The one your database uses. It matters for quoting, special operators and keywords: MySQL uses backticks for names, SQL Server uses square brackets and PostgreSQL has operators such as ::. Standard SQL suits simple queries.

What does the XML validator check?

Well-formedness, the rules every XML parser enforces: one root element, matching and properly nested tags, quoted and unique attributes, no bare & or < in text, only defined entities, valid names, comments without a double hyphen, and namespace prefixes that have been declared. It does not check a document against a DTD or XML Schema, so it cannot tell you whether an element is allowed in a given place.

Which GraphQL does the formatter handle?

Queries, mutations, subscriptions and fragments, and schema definitions (type, input, enum, interface, union, scalar, directive and extend). Format puts each field on its own line with arguments kept on one line; Minify removes comments, commas and extra spaces, which GraphQL ignores. Strings and block strings are kept exactly as written.

Is my code uploaded?

No. Formatting and minifying happen in your browser, so private code and configuration never leave your device.

About this tool

About the code formatter and minifier

Code copied from a minified bundle, a database log or a colleague with different editor settings can be unreadable. This tool reformats it with consistent indentation, or does the opposite and squeezes it down for production.

Languages

  • HTML, CSS and JavaScript are formatted with js-beautify. JavaScript is minified with Terser, the engine most build tools use.
  • SQL is formatted with sql-formatter. Choose your database dialect, such as MySQL, PostgreSQL or SQL Server, and upper or lower case keywords.
  • XML and YAML are reindented, and Validate checks that XML is well formed, pointing to the line and column of the first problem.
  • GraphQL queries, fragments and schema definitions are formatted with one field per line, or minified with comments and commas removed.

Each library loads only the first time you use its tab, so the page stays light.

Things to know

The HTML minifier is cautious: it removes comments and spare spaces but leaves the contents of pre, textarea, script and style elements alone. YAML is formatted by reading it into data and writing it out again, so comments are lost; keep the original if they matter. The SQL dialect matters for quoting and operators: MySQL uses backticks, SQL Server square brackets.

How to use it

Pick the language, paste code or open a file, choose the indent, then press Format or Minify and copy or download the result.

Formatting and minifying happen in your browser, so private code never leaves your device.

Related tools