Skip to main content

YAML Formatter

Clean up and beautify YAML: re-indent to a consistent 2- or 4-space step, wrap or unwrap long lines, optionally sort keys alphabetically, switch between block and compact flow style, and strip comments — while preserving quoting, block scalars and (by default) comments. Handles multi-document (---) files. Runs entirely in your browser; nothing is uploaded.

Input

Drop a file or browse
One file · text
Or

Wrap long lines at this column. Use 0 to disable wrapping.

Output

Formatted YAML
 
Was this helpful?

Guides

The YAML Formatter cleans up and beautifies YAML documents. Paste in a config file with mixed indentation, stray whitespace, or inconsistent list styling, and it re-prints a tidy, consistently indented version — while keeping your quoting, block scalars, and comments intact. It works on anything from a small .yml snippet to a multi-document file separated by ---.

Everything runs in your browser. Your YAML is parsed and re-serialized locally with a real YAML parser (not a fragile regex), so nothing is uploaded to a server.

How to use it

  1. Paste your YAML into the input box, or upload a .yaml / .yml file.
  2. Adjust the formatting options (all optional — the defaults produce a clean 2-space document).
  3. Copy the formatted result or download it as a .yaml file.

The output updates automatically as you type or change an option.

Formatting options

  • Indent Size — re-indent the whole document to a consistent 2- or 4-space step, collapsing mixed indentation.
  • Collection StylePreserve keeps each list/map in its original block or flow (inline) style; Block expands everything onto its own line; Flow renders the document compactly, { key: value } and [ a, b ] style, which acts as a lightweight YAML minifier.
  • Line Width — wrap long scalar values at this column. Set it to 0 to disable wrapping entirely and keep every value on one line.
  • Sort keys alphabetically — reorder mapping keys A→Z at every level. List items are never reordered, because a list's order is meaningful.
  • Strip comments — remove all # comments. By default comments are preserved and stay attached to the keys they document.

Why re-serialize instead of tweaking text?

A YAML file's meaning lives in its structure, not its whitespace. Formatting by find-and-replace is how config files get silently broken — a quoted "0755" file mode becomes octal 755, a country code "NO" becomes the boolean false, and multi-line block scalars get mangled. This tool parses your document into a proper syntax tree and prints it back out, so quoting, numeric types, and block text survive exactly as written. Invalid YAML is reported with the offending line rather than being reformatted into something wrong.

Does it preserve comments?

Yes, by default. Comments are reattached to their keys after reformatting. Turn on Strip comments if you want them removed.

Can it minify YAML?

Set Collection Style to Flow. The document is rendered in compact inline form, which is the closest YAML equivalent to minification. Combine it with a high or 0 line width to keep collections on single lines.

Does it handle multi-document files?

Yes. Documents separated by --- are each formatted independently and rejoined, so Kubernetes-style bundles and other multi-doc streams are supported.

yamlformatterbeautifierprettifyindentationyaml-linterminify

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.