Why format YAML?
YAML config files drift over time. One engineer prefers 4 space indents, another prefers 2. One sorts keys alphabetically, another groups them logically. Pull requests fill up with whitespace-only changes that drown out the real edits. Running every YAML file through a single formatter with consistent options eliminates this noise.
What the formatter changes
- Indentation - normalized to your chosen width (2 or 4 spaces) at every level.
- Trailing whitespace - removed from the end of every line.
- Key sorting - optionally alphabetized map keys at every nesting level for deterministic output.
- Quoting - quotes are added or removed based on whether the YAML 1.2 spec requires them for the value type.
- Anchor expansion - aliases (
*name) are resolved to their referenced values by default. Toggle Preserve anchors to keep&name/*namein the output.
What the formatter cannot preserve
The default formatter operates on the parsed data tree, so it cannot preserve comments or original document order. With Preserve anchors enabled, anchors and aliases are kept; comments still drop. If round-trip comment preservation matters, use a formatter built into a code editor (such as Prettier with the YAML plugin) that walks the source tokens instead.
FAQs
What does the YAML formatter do?
It parses your YAML, normalizes whitespace and indentation, optionally sorts keys alphabetically, and emits clean output that follows the YAML 1.2 spec. Trailing whitespace is removed and inconsistent indentation is fixed automatically.
How do I beautify YAML?
Paste your messy YAML, choose 2 or 4 space indentation, optionally toggle sort keys, and the formatter returns a properly indented version. Click Copy or Download to grab the output.
Will formatting break my anchors and aliases?
Anchors and aliases are resolved during formatting. The output is the fully expanded structure. If you need to preserve anchor references in the output, use the YAML editor instead and rely on it for whitespace cleanup only.
Does the formatter preserve comments?
No. The underlying parser produces a data tree without comment nodes, so comments are dropped during formatting. If keeping comments matters, use a code editor with a YAML formatter extension that operates on the source text.
Why use a YAML formatter for diffs?
When two team members format their YAML differently, every commit produces noisy diffs. Running everything through a single formatter with sort keys enabled yields deterministic output, so diffs only show real changes.
What indentation should I use?
Use 2 spaces. It is the YAML community default and what Kubernetes, GitHub Actions, Docker Compose, and most YAML tools assume. 4 spaces is sometimes used in Ansible playbooks but is not required.
Is the formatter safe for large files?
Yes, up to 5 MB. For larger files, format them in your IDE or run a CLI formatter as part of your build pipeline.
Does the formatter validate YAML at the same time?
Yes. Formatting requires parsing the input, so any syntax errors are surfaced with the exact line and column number, just like the dedicated YAML validator.
Can I sort keys for cleaner diffs?
Yes. Toggle the Sort keys option to alphabetize map keys at every nesting level. The result is deterministic, which makes pull-request reviews much easier.
Is the formatter sent to a server?
No. Parsing and formatting run entirely in your browser, so your YAML never leaves your device. The tool is safe for secrets and proprietary infrastructure config.