YAML Formatter.

Paste messy YAML and press Format. Indentation becomes consistent; comments and values stay exactly as you wrote them.

How it works

Layout changes, data does not

The formatter reads your file into a syntax tree that remembers comments, quoting and document boundaries, then writes it back with one consistent layout. Before the result reaches the editor, it is parsed again and compared with the original: if the data differs in any way, the editor is left untouched. Press Ctrl+Z to undo a format.

Before

# Staging deployment
services:
    web:
        image:   "nginx:1.25"   # pinned
        ports:
        - "8080:80"
        environment:
            REGION: NO
            VERSION: 3.10
    worker: &worker
        image: app:latest
        command: [run,   --queue, default]
    worker-eu:
        <<: *worker
        region: eu-west-1

After

# Staging deployment
services:
  web:
    image: "nginx:1.25" # pinned
    ports:
      - "8080:80"
    environment:
      REGION: NO
      VERSION: 3.10
  worker: &worker
    image: app:latest
    command: [ run, --queue, default ]
  worker-eu:
    <<: *worker
    region: eu-west-1
What it changes

One consistent style

  • Indentation becomes two spaces per level, and list items are indented under their key.
  • Spacing after colons and commas becomes one space, so [a, b] turns into [ a, b ].
  • A comment at the end of a line keeps one space before the #.
  • Long lines are never wrapped, so a long command or URL stays on one line.
What it keeps

Everything that carries meaning

  • Comments, both on their own line and at the end of a line. A comment after a key that opens a nested block moves to the line below it.
  • Multi-document files: every --- separator and ... end marker.
  • Anchors, aliases and merge keys such as &defaults, *defaults and <<:.
  • Values as written: 3.10 stays 3.10, 0123456 keeps its leading zero, and quoted or unquoted strings keep their quotes. Unquoted values that some parsers read as booleans or numbers, like NO, are left alone; Validate warns about them, see YAML gotchas.
  • Block scalars | and >, with their chomping indicators.
  • Tags such as !Ref and !Sub in CloudFormation templates, or !reference in GitLab CI.

If the YAML does not parse, nothing is formatted: you see the error and its line instead, as with Validate. Everything runs in your browser; the file is never uploaded.

Validate YAML against a schema
FAQ

Formatter questions

Can I change the indentation width?

No. The output always uses two spaces per level, with list items indented under their key, so every file comes out in the same style.

Does the formatter sort keys?

No. Keys stay in the order you wrote them, and so do list items. Only indentation and spacing change.

What happens if my YAML is invalid?

Nothing is formatted. You see the parse error and its line, the same as with Validate, and the editor keeps your text as it was.