# YAML Formatter

> Validate and reformat YAML, keeping comments and anchors. Multi-document files work. Runs entirely in your browser, so nothing is uploaded.

Source: https://toffeekit.com/tools/yaml-formatter

**Category:** [Developer](https://toffeekit.com/category/developer) · **Price:** Free · **Runs:** in your browser, nothing is uploaded

Open the tool: https://toffeekit.com/tools/yaml-formatter

**Also useful for:** yaml formatter, yaml validator, yaml lint, yaml beautifier, format yaml, yml validator, kubernetes yaml, docker compose yaml

## What you can do

- **Tidy Kubernetes YAML** — Two-space indent with list items flush under their key. ([open with this preset](https://toffeekit.com/tools/yaml-formatter?preset=k8s))
- **Expand inline lists** — Turn { } and [ ] flow style into block style. ([open with this preset](https://toffeekit.com/tools/yaml-formatter?preset=tidy))
- **Sort keys** — Order every mapping A to Z for cleaner diffs. ([open with this preset](https://toffeekit.com/tools/yaml-formatter?preset=sorted))

## How it works

1. Paste YAML into the input, or click Open to load a .yaml or .yml file.
2. Choose an Indent and whether list items are indented under their key.
3. Turn on Sort A to Z, Expand { } and [ ], or Fold at 80 chars if you need them.
4. Check the status line for errors or warnings, then Copy or Save the result.

## FAQ

### How do I validate a YAML file?

Paste it in. Errors show the line, column and a snippet of the problem, such as bad indentation, a tab character or a duplicate key.

### Are comments kept when formatting?

Yes. Comments, anchors (&name), aliases (*name) and merge keys (<<) are kept, because the file is reformatted rather than converted to data and back.

### Why are tabs an error in YAML?

The YAML spec forbids tabs for indentation. Replace them with spaces, usually two per level.

### Can it handle multiple documents in one file?

Yes. Documents separated by --- are each validated and formatted, which suits Kubernetes manifests with several resources.

### What does Indent list items under key change?

On, list items are indented under their parent key. Off, the dash lines up with the key, which is the style kubectl and many Kubernetes examples use. Both are valid YAML.

### Is YAML Formatter free and private?

Yes. It's free with no sign-up or limits, and it runs entirely in your browser, so what you type or paste never leaves your device. It works on phones and computers alike.

## Privacy

YAML Formatter runs entirely in your browser. Your files and text are processed on your device and are never uploaded.

## Related tools

- [JSON Formatter](https://toffeekit.com/tools/json-formatter) — Format, minify and validate JSON with clear errors.
- [Base64 Encode / Decode](https://toffeekit.com/tools/base64-encoder) — Encode text to Base64 or decode it back, UTF-8 safe.
- [URL Encode / Decode](https://toffeekit.com/tools/url-encoder) — Percent-encode query values or whole URLs.
- [HTML Entities](https://toffeekit.com/tools/html-entity-encoder) — Escape < > & and quotes, or decode entities.
- [JWT Decoder](https://toffeekit.com/tools/jwt-decoder) — Read a token's header, claims and expiry.
- [Hash Generator](https://toffeekit.com/tools/hash-generator) — MD5, SHA-1, SHA-256, SHA-384 and SHA-512 at once.

