What is YAML Formatter?
This YAML formatter rewrites YAML files with clean, consistent indentation. Inconsistent indentation is the most common reason a YAML file breaks or means something different from what you intended, because YAML uses indentation to express nesting. Paste your YAML and the formatter parses it, then writes it back out with 2 spaces per level, one key: value pair per line and every list item on its own - line.
It works with real-world files such as Kubernetes manifests, GitHub Actions workflows and docker-compose.yml: nested mappings, lists of objects, multi-line strings, anchors and aliases, and multiple documents separated by --- are all supported. If the input is not valid YAML, you see the parser's error with its line number instead.
How to use YAML Formatter
- Paste your YAML into the input panel.
- The formatted YAML appears in the output panel instantly.
- If an error is shown instead, fix the reported line; the YAML Validator explains each error.
- Copy or download the formatted YAML.
Key features
- Consistent 2-space indentation for mappings and lists
- Handles lists of objects, block strings, anchors and multiple documents
- Keeps values that could change type quoted, such as "yes" and "3.10"
- Shows the parser error and line for invalid YAML
- Instant output as you paste
- Runs in your browser; configuration secrets stay private
Common use cases
- Fixing mixed indentation in application settings files
- Normalizing hand-edited configuration before committing it
- Tidying environment and feature-flag YAML
- Checking how nested YAML mappings are interpreted
Technical details & standards
The input is parsed with a full YAML 1.2 parser and serialized again, so the output reflects the actual data rather than the original layout. Mappings and lists are written in block style with 2-space indentation, flow collections such as [80, 443] become block lists, and multi-line strings become literal blocks (|). Strings that would otherwise be read as another type, such as "yes", "3.10" or "007", stay quoted so their meaning does not change, and multiple documents keep their --- separators.
Because the YAML is rebuilt from its data, comments are not kept, and anchors, aliases and merge keys (<<: *defaults) are expanded into the values they stand for. Key order is preserved. Keep a copy of the original if its comments or anchors matter, or use an editor formatter such as Prettier, which formats the text without re-serializing it.
Format a YAML deployment setting
Try this input in the workspace above.
- Paste replicas: 2 followed by a new line containing image: nginx:1.27. Then choose the formatter’s indentation before copying the result.
Result: The output keeps replicas as the number 2 and image as the string nginx:1.27. If the parser reports an indentation error, replace any leading tabs with spaces and align sibling keys.
Frequently asked questions
How many spaces should YAML use for indentation?
Any consistent number of spaces works, but 2 spaces is the most common convention (used by Kubernetes, GitHub Actions and Docker Compose examples). Tabs are not allowed.
Does the formatter support lists and multi-line strings?
Yes. Lists, including lists of objects, are written as indented - items, and multi-line strings are kept as literal (|) blocks, so line breaks inside them are preserved.
Why did my comments and anchors disappear?
The formatter rebuilds the YAML from its parsed data. Comments are not part of that data, and anchors and aliases are replaced by the values they refer to. The meaning of the file is unchanged, but keep a copy of the original if you need its comments.
How can I check whether my YAML is valid?
If the formatter shows output, the YAML parsed. The YAML Validator gives a focused error message with the line number, and your platform's tooling, such as kubectl --dry-run or docker compose config, checks field names and types.
Is my data safe?
Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.
Does it work offline?
Once the page has loaded, this tool can process input without an internet connection.