YAML Formatter

Format YAML with Prettier: consistent indentation and spacing while comments and multiple documents are preserved. Syntax errors show line and column.

Output

Runs entirely in your browser. Your data is never uploaded.

Related Tools

View All

What is YAML Formatter?

The YAML Formatter normalises indentation and spacing of YAML files such as Kubernetes manifests, GitHub Actions workflows or Docker Compose files. Unlike converters that load and dump the data, it keeps comments, document separators (---) and key order.

How to use YAML Formatter

  1. Paste YAML into the input box or click Load sample.
  2. Choose the Indentation (2 spaces is common for YAML).
  3. Click Format (the output also updates while you type).
  4. Copy or download the formatted YAML.

Example

Input
a:   1
b:
      - x  # note
Output
a: 1
b:
  - x # note

When to use YAML Formatter

Use it to fix inconsistent indentation, tidy CI/CD and Kubernetes files or check YAML before committing. Tabs are not allowed for YAML indentation, so the Tab option is not recommended. To check syntax only, use the YAML Validator.

How YAML Formatter works

The input is first loaded with js-yaml to detect errors (including duplicate keys) with exact line and column. It is then printed with Prettier's YAML plugin, which works on the concrete syntax tree, so comments, anchors, multi-line strings and flow collections are kept while indentation and spacing are normalised.

Common Use Cases

  • Normalising Kubernetes or Helm values files
  • Tidying GitHub Actions workflows
  • Fixing mixed indentation in docker-compose.yml
  • Formatting YAML examples for documentation

Security Note

Everything runs locally in your browser; the code you paste is not uploaded.

FAQs

Are comments kept?

Yes, comments are preserved.

Does it change key order?

No.

Why does it reject duplicate keys?

YAML 1.2 requires unique keys in a mapping, so js-yaml reports them as errors.

Explore more categories