YAML Formatter
A YAML formatter re-indents YAML consistently and tells you exactly where it is broken. Paste or drop a .yaml or .yml file, pick 2- or 4-space indent, optionally sort keys, then copy or download the clean YAML. Invalid YAML shows the line and column. Nothing is uploaded.
Updated
This page parses your YAML with js-yaml (YAML 1.2 core schema) in your tab and writes it back out with one indentation style: nested maps and lists line up, extra spaces after colons go, and flow lists like [80, 443] become block lists. Key order is kept unless you tick Sort keys, which sorts every mapping alphabetically — handy before diffing two Kubernetes manifests or docker-compose files. Strings that only look like numbers or booleans, such as '600001' or 'yes', stay quoted so their type does not change. Multi-document streams separated by --- stay separate documents.
If the YAML is invalid you get the parser's reason with a 1-based line and column and a snippet pointing at the spot — tabs used for indentation, a key indented one space too far, a duplicate key, or an unclosed bracket. Because the formatter parses and re-writes, # comments and anchors are not carried into the output (anchors are expanded); keep your original if they matter. This is a formatter and validator, not a JSON↔YAML converter and not a Kubernetes or OpenAPI schema checker. Nothing is fetched, uploaded, or written to localStorage.
Paste YAML (spaces, not tabs). Drop a .yaml or .yml file — it stays in this tab.
Optional .yaml or .yml file. Read with FileReader in this tab — never uploaded.
Formatted YAML
Converting between formats instead? Use JSON to YAML. Tidying JSON? Use JSON Formatter.
How does the YAML Formatter work?
1. Paste or drop YAML
Paste YAML, drop a .yaml or .yml file, or press Load example for a small fictional deploy config. Files are read with FileReader in this tab — never uploaded.
2. Pick indent and key order
Choose 2 spaces (the common default for Kubernetes, GitHub Actions, and docker-compose) or 4 spaces. Tick Sort keys to sort every mapping alphabetically; leave it off to keep your original order.
3. Fix any errors
Invalid YAML shows the reason with line and column plus a snippet that points at the problem — usually a tab, a mis-indented key, a duplicate key, or an unclosed bracket. The output updates as soon as it parses.
4. Copy or download
Copy the formatted YAML or download it as a .yaml file. Re-add any # comments you need, because the formatter re-writes the document. Closing the tab drops the workspace.
Questions about YAML Formatter
- What does a YAML formatter do?
- It parses your YAML and writes it back with consistent indentation and spacing, so nested keys line up and the file is easier to read and review. Because it has to parse the document first, it also validates it: if the YAML is broken you get an error with the line and column instead of output.
- How do I validate YAML and find the error line?
- Paste the YAML. If it parses, the status line says Valid YAML with the document and line count. If not, the error names the problem — for example bad indentation of a mapping entry, duplicated mapping key, or tabs used for indentation — with a 1-based line and column and a snippet marking the spot. Fix that line and the formatted output appears.
- Why does YAML reject tabs?
- The YAML spec only allows spaces for indentation, because tab width differs between editors and would make nesting ambiguous. If your file uses tabs, the formatter reports the line; replace the tabs with spaces (2 per level is the usual choice) and it will format.
- Should I use 2 or 4 spaces in YAML?
- Either is valid as long as each file is consistent. Two spaces is the convention in Kubernetes manifests, GitHub Actions workflows, docker-compose, and Ansible, so it is the default here. Pick 4 if your team's style guide asks for it.
- Does it keep my comments and key order?
- Key order is kept unless you turn on Sort keys. Comments are not: the formatter parses the YAML into data and writes it back, and # comments are not part of that data, so they are dropped (the page warns you when your input had comments). Anchors and aliases are expanded into full copies. Keep your original file if comments or anchors matter.
- Will formatting change my values?
- No values change. Strings that look like numbers, dates, or booleans — '600001', '1.10', 'yes' — stay quoted so they remain strings. Unquoted values are read with the YAML 1.2 core schema, so yes/no/on/off stay strings rather than turning into booleans as in old YAML 1.1 parsers. Long strings are not folded.
- Can it format multi-document YAML files (---)?
- Yes. A stream with several documents separated by --- is formatted document by document, and the output keeps a --- line before each one. This is common in Kubernetes files that bundle a Deployment and a Service together.
- Does it upload my YAML, and how is it different from JSON to YAML?
- Nothing is uploaded: parsing and formatting run in this tab, nothing is written to localStorage, and closing the tab drops the text — safe for configs with internal hostnames. JSON to YAML is a converter between two formats; YAML Formatter keeps YAML as YAML and only tidies and validates it. There is one canonical address, /developer/yaml-formatter/, which also covers searches like yml formatter or yaml beautifier.
What else can I open?
- JWT Token DecryptDecrypt a compact JWE locally with Web Crypto.
- JSON Schema GeneratorGenerate a JSON Schema from a JSON sample in the browser — no upload.
- JSON to YAMLConvert JSON to YAML or YAML to JSON in the browser.
- JSON FormatterTidy, validate, and pretty-print JSON locally.
- XML FormatterPretty-print or minify XML in your browser.
- Code DiffCompare two pastes line by line in the browser.
These tools run in your browser. Page Utils does not store, upload, or write to localStorage the keys, tokens, or text you paste. Results are a convenience aid, not legal, tax, or security advice.