Comparison

Minify, format and validate are three different operations

All three take code in and give code back, which is why they get used interchangeably. Only one of them is meant for the file you ship, only one is meant for the file you read, and the third never changes a byte.

15 related tools

Side by side

Minify, format and validate are three different operations
OperationChanges the file?Output is forReversible
MinifyYes, removes whitespace and commentsThe browserFormat it again
Format / beautifyYes, adds whitespaceA human and a diffMinify it again
ValidateNoFinding the errorNothing to reverse

The short answer

Minify what you deploy, format what you commit, validate when something will not parse. Two cautions: minifying strips comments, so a licence header disappears unless it is marked to keep; and in HTML, whitespace between inline elements is not decoration, so a minifier that collapses it can visibly close up gaps between words and links.

In more detail

Whitespace is not always decoration

In HTML, the space between two inline elements renders as a space, so a minifier that removes it closes up the gap between words or links. Good minifiers know this and leave it; aggressive settings sometimes do not. In pre and textarea elements every character is significant, and in YAML and Python indentation is syntax.

Minify what you deploy, commit what you can read

A minified file in version control produces a diff nobody can review, which is how a change hides in a one-line file. Keep the readable version in the repository, minify as part of the build, and let the build output be the thing that ships. If a minified file is already committed, formatting it once is a safe one-off.

Validation changes nothing, which is the point

A validator reads and reports; it never writes. That makes it the right first move when something will not parse, because it tells you the line and the character rather than quietly producing something that looks plausible. It is also why running one costs nothing and is worth doing before any conversion.

Tools covered by this comparison

JSON Formatter & Beautifierdeveloper · Format, indent, beautify, and validate JSON data, with the exact position of any syntax errorJSON Validatordeveloper · Validate JSON syntax against RFC 8259 standards and pinpoint exact line and character errorsJSON Minifierdeveloper · Remove all unnecessary whitespace, indentations, and newlines to shrink JSON payload sizeJSON Beautifierdeveloper · Re-indent minified JSON at a width you choose, from no indent up to eight spacesHTML Formatterdeveloper · Format, indent, and organize messy HTML code with clean tag hierarchy and spacingHTML Minifierdeveloper · Remove comments, collapse whitespace, and strip redundant quotes to speed up website page loadsCSS Formatterdeveloper · Format, indent, and organize CSS stylesheets with uniform selector rules and property spacingCSS Minifierdeveloper · Compress CSS stylesheets by removing whitespace, comments, and optimizing hex color valuesJavaScript Formatterdeveloper · Format, de-minify, and beautify minified JS and TypeScript code with customizable indentationJavaScript Minifierdeveloper · Minify JavaScript code to reduce bundle size, strip dead comments, and optimize production payloadsSQL Formatterdeveloper · Lay a SQL query out across lines with its clauses aligned and keywords capitalisedSQL Minifierdeveloper · Compress multi-line SQL queries into single-line strings ready for embedding in code and migrationsXML Formatterdeveloper · Format, indent, and prettify XML documents, RSS feeds, SOAP payloads, and SVG filesXML Validatordeveloper · Validate XML syntax and check for unclosed tags, attribute errors, and malformed entity referencesYAML Formatterdeveloper · Re-indents, and finds the scalars two parsers disagree about

More comparisons