# YAML Formatter

Format and validate YAML, with the line and column of any error. Anything it prints is guaranteed to parse. Nothing you paste is uploaded.

Canonical page: https://filetity.com/yaml-formatter

## Capabilities

- Free: Yes, with no watermark and no page limit.
- Account required: No. There is no account system.
- Processed on device: Yes. The file is read by your browser and never uploaded. There is no server to send it to.
- Formats: YAML in, including anchors, aliases and multi document streams. Formatted YAML out, two or four space indented, keys optionally sorted.
- Limits: Comments do not survive, because the parser does not keep them. That is the one real cost of formatting by re-printing rather than by rewriting the text in place.
- Mobile: Yes, on any modern mobile browser. Large files are limited by the memory the phone gives the browser.
- Offline: Yes, once the page has loaded. The tool keeps working with no network connection.

## Questions

### Why do my comments disappear?

Because formatting works by parsing the document and printing it again, and the parser does not keep comments: they are not part of the data. That round trip is also what guarantees the output parses. A formatter that preserved comments would have to rewrite the text in place and could not make that promise.

### Does this validate as well as format?

Yes, as a side effect. A document that will not format is a document that will not load, so if you get formatted output the YAML is valid. If you get an error, it carries the line and column where parsing stopped and what was wrong there.

### Why is a tab an error when spaces are fine?

Because the YAML specification forbids tabs for indentation entirely. It is not a preference: a tab in the indentation makes the document invalid. Editors that insert tabs silently are the usual cause, and it is invisible in most of them.

### Should I sort the keys?

Only when you are about to compare two files. Sorting makes two documents comparable regardless of the order their keys were typed in, which is genuinely useful for a diff. It is off by default because key order is often meaningful to a person reading a config, even though YAML itself does not care.

### What happens to a file with several documents in it?

Each is formatted and the count is reported. A stream separated by three dashes is normal in Kubernetes output, and none of them are dropped, which is what a naive load-and-dump does when it keeps only the first.

## Related tools

- [YAML to JSON](https://filetity.com/yaml-to-json): Convert YAML to JSON, including multi document streams.
- [JSON Formatter and Validator](https://filetity.com/json-formatter): Format, beautify, validate and read JSON, and find the line that broke it.
