Code Formatters
The code formatters take SQL, HTML, YAML or XML that arrived on one line or with drifting indentation and print it back in a consistent layout. They are for reading and reviewing: a query copied from an ORM log, markup from a CMS, a Kubernetes manifest, a SOAP response or an RSS feed. JSON lives in the Data Conversion group, in the JSON Formatter.
4 free tools · no sign-up · no ads
All Code Formatters (4)
Which tool do I need?
Read a long SQL query copied from a log
The SQL Beautifier breaks the query at SELECT, FROM, JOIN, WHERE and the other major clauses and indents AND, OR and ON conditions under them.
Find the syntax error in a YAML file that will not deploy
Paste it into the YAML Beautifier. Invalid YAML produces the parser message with a line and column instead of output.
Pull a value out of an XML response
The XML Beautifier checks well-formedness, pretty-prints, and runs XPath expressions such as //book[@id='1']/title against the same document.
Make minified HTML readable before editing it
The HTML Beautifier puts each block element on its own line with two-space indentation while keeping inline content and pre blocks exactly as they were.
About Code Formatters
The four tools work in two different ways, and that decides what they can tell you. The YAML and XML beautifiers parse the document first, YAML with a full YAML 1.2 parser and XML with the browser's DOMParser. If the input is broken you get the parser's error instead of output, so they double as syntax checks, and the XML tool adds an XPath query panel. The SQL and HTML beautifiers are tolerant formatters that work on keywords and tags without a full grammar. The SQL one handles any dialect but does not indent subqueries by depth or report syntax errors, and the HTML one prints unclosed tags where they appear rather than flagging them.
All four are careful with content where whitespace is data: SQL string literals and comments, HTML inside pre, textarea, script and style, XML text nodes and xml:space="preserve", and YAML comments, anchors and block scalars. None of them validates against a schema. A YAML file can be well-formed and still contain a misspelled Kubernetes field, and well-formed XML is not the same as XML that matches its XSD. A useful habit is to format both versions of a file before you diff them, so the Online Diff Tool shows structural changes instead of one changed line.
Guides
- SQL Formatting Conventions That Make Queries Easier to ReviewClause-per-line layout, keyword casing, join alignment and CTEs. A practical style guide for SQL that your teammates can read at 2 a.m. during an incident.
- Formatting HTML, XML and YAML Without Changing What They MeanWhere whitespace is safe to move in HTML, XML and YAML, where it is data, and the formatter bugs (void tags, mixed content, duplicate keys) that quietly change files.
Frequently asked questions
Can a code formatter break my file?
These formatters are designed not to, by leaving whitespace-sensitive content alone. Two small exceptions are worth checking: the HTML Beautifier re-indents script blocks as a whole, so a multi-line template literal inside a script can lose leading spaces, and the YAML Beautifier normalises the spacing before inline comments, which removes column alignment.
Which of these formatters also check syntax?
The YAML and XML beautifiers do, because they parse the document before printing it and refuse invalid input with a line and column. The SQL and HTML beautifiers are tolerant: they format what they are given and do not report syntax errors or unclosed tags.
Why is JSON not in the code formatters group?
JSON formatting lives in Data Conversion as the JSON Formatter, which validates with JSON.parse, pretty-prints or minifies, and runs JSONPath queries. It sits there because JSON work usually continues into a conversion to YAML or CSV, or into TypeScript types.
Should I use an online formatter or one in my editor or CI?
Use an online formatter for one-off reading, such as a query from a log or a manifest from a ticket. For files in a repository, run a formatter in your editor and CI, such as Prettier, sqlfluff or pgFormatter, so every commit follows the same style without manual steps.
What indentation do the beautifiers produce?
The HTML, YAML and XML beautifiers indent by two spaces per nesting level. The SQL Beautifier starts a new line at each major clause, upper-cases clause keywords and indents AND, OR and ON conditions. YAML must be indented with spaces, never tabs.