Skip to content
Toolew.com

YAML Formatter

Re-indent and tidy YAML, expand inline collections, normalise quotes and sort keys while keeping anchors, tags and block scalars.

Runs in your browser. Your data is not uploaded.
Loading tool…

This guide is not yet available in your language and is shown in English.

Tool guide

What this tool does

YAML Formatter validates YAML and rewrites it with consistent 2 or 4 space indentation. It can expand inline [ ] and { } collections into block style, remove unnecessary quotes or switch quote style, and sort keys, while preserving anchors, aliases, explicit tags, literal and folded blocks and multiple documents. Errors show the line and column.

YAML files grow messy as several people edit them: some sections use 4 spaces and others 2, list items are indented under their key in one place and not in another, and inline { } maps sneak in next to block ones. Because indentation is the structure in YAML, inconsistent spacing is not just ugly; it is where most parse errors come from.

This formatter parses the document with js-yaml into a syntax tree and prints it again with the layout you choose. Working from the tree rather than converting to plain data means anchors (&name) and aliases (*name) stay as references, explicit tags like !!binary remain, literal (|) and folded (>) blocks keep their style and multiple --- documents are preserved. When quotes are removed, the formatter uses YAML 1.1 rules to decide what is safe, so words like on, yes and no stay quoted for older parsers. Comments are not carried over, and a notice tells you when the input contained any. Everything runs locally.

How to use YAML Formatter

  1. Paste YAML into YAML input, open a .yaml or .yml file, or click Sample.
  2. Choose the Indentation and whether list items should be indented under their key.
  3. Decide whether to keep inline [ ] and { } collections or expand them to block style.
  4. Pick how String quotes are handled: keep, remove unnecessary quotes, or prefer single or double quotes.
  5. Optionally sort keys and set the line width for long strings.
  6. Fix any reported line and column errors, then copy or download formatted.yaml.

Tips for better results

  • Format once with your team’s settings before a large edit, commit that separately, and later diffs will show only real changes.
  • Keeping inline collections is useful for short lists such as branches: [main], which many style guides prefer on one line.
  • In GitHub Actions the key on is quoted as 'on' because YAML 1.1 parsers read a bare on as true; both forms work in Actions.
  • Run the result through YAML to JSON to check that the data is unchanged.

Common use cases

  • Cleaning up Kubernetes manifests and Helm values before review.
  • Normalising GitHub Actions, GitLab CI or CircleCI pipeline files.
  • Checking Docker Compose or Ansible files for indentation errors.
  • Standardising OpenAPI specifications written by several contributors.

Common mistakes to avoid

  • Replacing a heavily commented file with the formatted output without copying the comments you need.
  • Mixing tabs into indentation; YAML forbids tabs, and the error will point to the line.
  • Sorting keys in files where order is meaningful to people, such as apiVersion and kind at the top of Kubernetes resources.

Frequently asked questions

Are comments preserved?

No. The formatter rebuilds the document from a parsed syntax tree, and the parser does not keep comments. A notice appears when the input has comments so you can keep a copy of them.

Will anchors and aliases be expanded?

No. Anchors and aliases stay as they are, so &defaults and *defaults remain references instead of duplicated data. Use YAML to JSON if you want to see the expanded values.

Why did some quotes stay after choosing Remove unnecessary quotes?

Quotes are kept where removing them would change the type of a value, such as "123", "true", "null" or "yes", or where the string starts with a character that has special meaning in YAML, such as * or &.

Does it support multiple documents?

Yes. Files containing several documents separated by --- are formatted document by document and the separators are kept.

Feedback & suggestions

Help us improve YAML Formatter. We read every message.

Rating (optional)
Necessary
Required for security, language and theme preferences. Always on.