How to format YAML with this tool
- Paste your YAML into YAML input. The page opens with an unevenly indented file so you can see the result at once.
- Choose Indent: 2 or 4 spaces.
- Keep Indent list items under their key ticked to indent list dashes under the key. Clear it to line them up with the key, as many Kubernetes files do.
- Keep Convert tab indentation to spaces ticked to repair tab-indented files, which YAML does not allow.
- Read the line under Formatted YAML. Green means valid. Red gives the line, column and reason for the first error, and Show error moves the cursor there.
- Click Copy result.
How the checking and formatting work
The page loads the open source yaml library (version 2.9.1, ISC licence) and parses your text as YAML 1.2. That gives exact positions for bad indentation, unclosed brackets, duplicate keys and aliases with no anchor. The parsed document is then written back with your indent. Comments, blank lines between sections, quote styles, block scalars, anchors, aliases and merge keys are kept. Plain values are copied as you typed them, so 1.0, 3.10, 0644 and yes are never rewritten as 1, 3.1, 644 or true.
Worked example
With the defaults (2 spaces, list items indented, tabs converted), this input from the page:
# Service settings
name: example
version: 1.0
services:
- web
- db
config:
debug: true
port: 3000
becomes:
# Service settings name: example version: 1.0 services: - web - db config: debug: true port: 3000
The status line then reads: Valid YAML. 1 document. Formatted with a 2-space indent.
Limits and edge cases
- The tool checks YAML syntax only. It cannot tell whether a file is a valid Kubernetes manifest or GitHub Actions workflow; use a schema-aware checker such as kubeconform or actionlint for that.
- Only the layout changes, but some of it does. Folded blocks (
>) may join their lines and a flow list written over several lines becomes one line. The values stay the same. - Only leading tabs that cause an error are converted to spaces. Tabs inside values are never turned into spaces.
- Clearing the list option gives dashes level with the key at 2 spaces. At 4 spaces they sit 2 columns in.
- The 105 KB parser downloads on first use from a CDN, without your YAML. If a blocker stops it, the page says so and offers a retry. A 1 MB file takes a few seconds.
Frequently asked questions
How do I find an indentation error in YAML?
Paste the file and read the red message under the result. It gives the line, column and reason for the first problem, such as mapping items that do not start at the same column. Click Show error to put the cursor there.
Why does YAML reject tabs?
The YAML specification allows only spaces for indentation, because tabs can display at different widths. With Convert tab indentation to spaces ticked, this tool replaces leading tabs when they cause the error and tells you which lines changed.
Does formatting keep my comments?
Yes. Comments, blank lines between sections, quote styles, anchors and aliases are kept. The tool changes the indentation and the spacing inside flow lists such as [1, 2, 3].
Why do yes and on turn into true in some tools?
YAML 1.1 parsers such as PyYAML read yes, no, on and off as booleans. This formatter checks YAML 1.2, where they are plain text, and leaves them as typed. Quote them if a 1.1 parser will read the file and you mean the words.
Can I format a Kubernetes or Docker Compose file?
Yes. Both are ordinary YAML. A file with several documents separated by three dashes is formatted one document at a time. Only YAML syntax is checked, not whether the keys are valid for Kubernetes or Compose.
Need another format? Try the YAML to JSON converter, the JSON formatter and validator, the XML formatter, or the diff checker to compare the file before and after.