02 / YAML / yaml-formatter

YAML Formatter

Format and re-indent YAML documents.

ReadyLocal processing
02 · Workspace

How to use

  1. 01Paste messy or inconsistently indented YAML into the YAML input box.
  2. 02Pick 2 spaces or 4 spaces under Indent.
  3. 03Optionally tick Compact (flow) style to write collections inline with braces and brackets instead of as indented blocks.
  4. 04Press Format YAML. The cleaned-up document appears under Formatted YAML.
  5. 05If the input can't be parsed, an Invalid YAML note shows the parser message and position. Fix it and press Format YAML again.
  6. 06Copy the result or press Download .yaml to save it as formatted.yaml.

What is this tool?

This YAML formatter parses your document and rewrites it with consistent indentation, spacing and collection style. It's the quickest way to normalize a file that several people have edited by hand. Inline lists like [8080, 9090] can be expanded into block lists, or a whole document can be collapsed into compact flow style. The document is fully parsed before it's rewritten, so you only get output for valid YAML. Formatting happens in your browser, and nothing is uploaded.

What the formatter changes and what it removes

The formatter rebuilds the YAML from its parsed data rather than adjusting whitespace in place. That gives very consistent output: extra spaces after colons are removed, nested maps are re-indented to the width you chose, and flow collections are expanded to block style (unless you tick Compact). For example, a document with service: orders-api, a 4-space-indented env block and ports: [8080, 9090] comes out with single spaces after colons, 2-space nesting, and ports written as a dash list.

Because it rebuilds from data, some source details don't survive. Comments are dropped. Anchors and aliases (&name and *name) are expanded, so each alias is replaced by a full copy of its content. Quoting style is also normalized, with quotes kept only where they're needed. Format a copy if your comments matter, or reapply them afterward.

Block vs flow style, and choosing an indent

Block style puts one key or list item per line, with nesting shown by indentation. It's what most people expect in Kubernetes manifests, Compose files and CI pipelines, and it gives the cleanest line-by-line diffs in code review. Flow style looks like JSON, as in { a: [ 1, 2 ], b: { c: 1 } }. It suits short, deeply nested values or pasting a config into a single line.

Two-space indentation is the common default across the YAML ecosystem. Four spaces can be easier to scan in long, deeply nested files. Either is valid, as long as one document doesn't mix tabs into its indentation. YAML forbids tabs, and the formatter reports them as an error.

Common use cases

  • Normalizing indentation in a docker-compose.yml that several developers have edited by hand
  • Expanding inline [a, b, c] lists into block lists before a code review so diffs are line-by-line
  • Cleaning up YAML pasted from a chat message or wiki page before committing it
  • Collapsing a small nested config into compact flow style for a CLI flag or environment variable
  • Standardizing a team's test fixture files on 2-space indentation

FAQ

How do I format or beautify YAML?

Paste the YAML, choose 2 or 4 spaces of indentation, and press Format YAML. The re-indented document appears on the right, ready to copy or download.

Does the YAML formatter keep my comments?

No. The document is parsed and written out again from its data, and comments aren't part of that data, so they're removed from the output.

What does Compact (flow) style do?

It writes maps and lists inline using { } and [ ], the way JSON does, instead of as indented blocks. Leave it unticked for conventional block-style YAML.

Why won't my YAML format?

The formatter only works on YAML that parses. Tabs used for indentation, duplicate keys, unclosed quotes and misaligned list items all produce an Invalid YAML message with a line and column.

Can I format a file with multiple --- documents?

No. The formatter handles one document at a time and reports an error when the input contains several. Format each document separately.