YAML Formatter
Format YAML with Prettier: consistent indentation and spacing while comments and multiple documents are preserved. Syntax errors show line and column.
Runs entirely in your browser. Your data is never uploaded.
Related Tools
View AllWhat is YAML Formatter?
The YAML Formatter normalises indentation and spacing of YAML files such as Kubernetes manifests, GitHub Actions workflows or Docker Compose files. Unlike converters that load and dump the data, it keeps comments, document separators (---) and key order.
How to use YAML Formatter
- Paste YAML into the input box or click Load sample.
- Choose the Indentation (2 spaces is common for YAML).
- Click Format (the output also updates while you type).
- Copy or download the formatted YAML.
Example
a: 1
b:
- x # note
a: 1 b: - x # note
When to use YAML Formatter
Use it to fix inconsistent indentation, tidy CI/CD and Kubernetes files or check YAML before committing. Tabs are not allowed for YAML indentation, so the Tab option is not recommended. To check syntax only, use the YAML Validator.
How YAML Formatter works
The input is first loaded with js-yaml to detect errors (including duplicate keys) with exact line and column. It is then printed with Prettier's YAML plugin, which works on the concrete syntax tree, so comments, anchors, multi-line strings and flow collections are kept while indentation and spacing are normalised.
Common Use Cases
- Normalising Kubernetes or Helm values files
- Tidying GitHub Actions workflows
- Fixing mixed indentation in docker-compose.yml
- Formatting YAML examples for documentation
Security Note
Everything runs locally in your browser; the code you paste is not uploaded.
FAQs
Are comments kept?
Yes, comments are preserved.
Does it change key order?
No.
Why does it reject duplicate keys?
YAML 1.2 requires unique keys in a mapping, so js-yaml reports them as errors.