What is a YAML formatter?
A YAML formatter rewrites a YAML file with consistent indentation and spacing while keeping the same data. Because indentation is part of YAML's syntax, hand-edited files easily drift: one block indented with 4 spaces, the next with 2, list items sometimes indented and sometimes not. A formatter normalises all of that so the file is easier to review and produces clean diffs. This one is built on a full YAML 1.2 parser that keeps comments, which plain YAML-to-data-to-YAML round trips lose.
How to format YAML
- Paste YAML or open a
.yaml/.ymlfile. It is checked as you type. - Choose 2 or 4 spaces and decide whether to sort keys alphabetically.
- Click Format. Copy or download the result, or convert it with To JSON.
Example
Input with mixed indentation and a comment:
services:
web: # public entry point
image: nginx:1.27
ports:
- "80:80"
db:
image: postgres:16
Formatted with 2 spaces:
services:
web: # public entry point
image: nginx:1.27
ports:
- "80:80"
db:
image: postgres:16
What the formatter changes and what it keeps
| Changes | Keeps |
|---|---|
| Indentation of mappings and sequences | Comments, including inline comments |
| Spacing after colons and dashes | Anchors, aliases, tags and merge keys |
| Key order, only when Sort keys is ticked | Quoting style of strings, block scalars |
| Flow collections are kept, with normalised spacing | Document separators (---) in multi-document files |
When the YAML is invalid
Formatting needs a document that parses. If it does not, the problems list shows the line and column of each error together with a plain explanation: a tab used for indentation, a key without a space after its colon, a line indented to a level that matches no parent, an unclosed bracket or quote, or a duplicate key. The YAML validator page explains each of these in detail. The formatter also warns about values that YAML 1.1 tools read differently, such as an unquoted no or 0755.
Need the same data in another format? Use YAML to JSON. Comparing two versions? Use the YAML diff.