What the YAML formatter does
YAML is the format behind Docker Compose files, Kubernetes manifests, GitHub Actions workflows, Ansible playbooks and many app configs. Its structure comes from indentation, so a single misplaced space can change what a file means or stop a deploy. This tool rewrites your YAML with consistent indentation and spacing, and checks it with a strict parser so problems show up here instead of in your pipeline.
It has two actions:
- Format normalises indentation, the spaces after colons and dashes, and the spacing inside
[ ]and{ }. - Validate parses the file and reports the first error, or a short summary when it is valid.
How to use it
- Paste YAML into the left box. It is formatted as soon as you paste. You can also use Open file for
.yamland.ymlfiles, or Sample for an example. - Choose an Indent of 2 or 4 spaces and a Line width.
- Turn on Single quotes if your project prefers
'text'over"text". - Press Format or Validate. Ctrl+Enter runs the last action again.
- Press Copy, or Download to save a
.yamlfile.
Before and after
A Docker Compose file with uneven spacing and 4-space indents:
version: "3.8"
services:
web:
image: "nginx:latest"
ports:
- "80:80"
environment:
- DEBUG=false
db:
image: postgres:16
After Format with 2 spaces:
version: "3.8"
services:
web:
image: "nginx:latest"
ports:
- "80:80"
environment:
- DEBUG=false
db:
image: postgres:16
Flow collections get even spacing. tags: [ api, v2 ] and limits: {cpu: 1, memory: 512} become:
tags: [api, v2]
limits: { cpu: 1, memory: 512 }
Comments survive. The extra spaces before an end-of-line comment are tidied, but the comment stays on its line:
# Database settings
db:
host: localhost # local only
port: 5432
With Single quotes on, name: "web" becomes name: 'web'. A string that contains an apostrophe, such as "it's here", keeps its double quotes so no escaping is needed.
Errors the validator catches
YAML parsers in different tools are not equally strict. This one flags problems that some tools let through. Real messages from the tool:
| Problem | Message |
|---|---|
| The same key twice | Line 3, column 1: Map keys must be unique |
| A tab used for indentation | Line 2, column 1: Tabs are not allowed as indentation |
| A line indented one space too far | Line 2, column 9: Nested mappings are not allowed in compact mappings |
The duplicate key check matters most. In a file such as name: web, port: 80, name: api, many loaders keep only the last name without a warning. Press Show in input to jump to the line.
For a valid file with two documents separated by ---, Validate reports: Valid YAML. 2 documents.
Tips and limits
- The formatter does not reorder keys or change values.
yes,onand010are left as you wrote them. - Long strings are not rewrapped. Folded (
>) and literal (|) blocks keep their content. - Anchors and aliases (
&name,*name) are kept as written. - YAML has no minified form in common use, so there is no Minify button. If you need compact data, convert it with the JSON to YAML Converter in the YAML to JSON direction.
Other ways to format YAML
VS Code. The Red Hat YAML extension adds formatting and schema checks for files such as Kubernetes manifests. Run Format Document after installing it.
yq. The Go version of yq (by Mike Farah) reads and rewrites YAML. yq '.' file.yaml prints the file back in its own consistent style, and the same tool can query and edit values.
Prettier. If your project already uses Prettier, it formats .yaml and .yml files with the same rules as this page.
yamllint. A Python tool that checks style and syntax without rewriting the file, useful in CI.
Related tools
To turn JSON into YAML or back, use the JSON to YAML Converter. For JSON files, use the JSON Formatter. For XML configs such as Maven or Android files, use the XML Formatter.