Skip to content

YAML Formatter

Turn messy YAML into clean, consistently indented YAML. Paste or upload a file, pick your indentation and style, and copy the result. Choose full reformatting to normalise everything, or tidy-whitespace mode to clean up spacing while keeping every comment. It all runs in your browser, so your files stay on your device.

Drop your YAML file here

or

Supports .yaml and .yml files up to 2 MB, processed entirely on your device

Untitled.yaml0 B0 lines0 characters

Formatted YAML

Waiting for YAML input.

What to expect

  • Re-indents with 2 or 4 spaces and converts inline lists and mappings to block style.
  • Optionally sorts keys alphabetically, wraps long lines and sets the quote style.
  • Tidy mode removes stray whitespace and keeps your comments untouched.
  • Refuses to format invalid YAML and tells you the line to fix instead.

How to use it

  1. 1

    Add your YAML

    Paste it into the editor, or drag in a .yaml or .yml file.

  2. 2

    Choose how to format

    Pick Reformat or Tidy whitespace, then set the indentation, line width, quote style and sorting.

  3. 3

    Copy or download

    The result updates live. Copy it, download it as a file, or send it back to the editor to keep working.

Before and after: what the formatter does

Each result below was generated by the formatter itself with the settings noted, so it shows exactly what you will get.

Inconsistent indentation becomes uniform

Mixed spacing, unindented list items and extra spaces after colons are normalised to a single consistent style, using two spaces by default.

Before
server:
    host: localhost
    ports:
    - 80
    - 443
database:
  name:   app
  pool:    {min: 2, max: 10}
Formatted YAML
server:
  host: localhost
  ports:
    - 80
    - 443
database:
  name: app
  pool:
    min: 2
    max: 10

Inline flow style becomes readable block style

A compact one-line mapping is expanded into the block layout people actually want to read and review in a diff.

Before
{name: demo, tags: [web, cli], env: {debug: true, level: info}}
Formatted YAML
name: demo
tags:
  - web
  - cli
env:
  debug: true
  level: info

Keys sorted alphabetically

Turn on Sort keys to order every mapping alphabetically at every level. This makes two versions of a file much easier to compare.

Before
zone: eu
name: demo
meta:
  version: 2
  author: Ada
alpha: 1
Formatted with sorted keys
alpha: 1
meta:
  author: Ada
  version: 2
name: demo
zone: eu

Tidy mode keeps your comments

Reformatting rewrites YAML from its data, which drops comments. Tidy whitespace mode only removes trailing spaces and extra blank lines, so every comment survives.

Before
# Service settings   
server:   
  host: localhost   # main host



  port: 8080
Tidied YAML
# Service settings
server:
  host: localhost   # main host

  port: 8080

Reformat or tidy whitespace: which should you pick?

Reformat parses your YAML into data and writes it back out in a uniform style. That gives you a guaranteed-consistent result with your chosen indentation, line width, quote style and key order, and it expands inline lists and mappings into block style. The trade-off is that comments are not part of the data, so they are removed. The formatter tells you whenever that happens.

Tidy whitespace works on the text itself. It converts Windows line endings to Unix, trims trailing spaces, collapses runs of blank lines and makes sure the file ends with one newline. It does not touch indentation or content, so every comment and every original line stays exactly as written. Choose it for heavily commented files such as CI workflows and Helm values.

What formatting never changes

Formatting should never change what your YAML means. Dates such as 2026-03-14 are kept as written rather than being rewritten as full timestamps, unquoted values stay unquoted unless the syntax requires quotes, and multi-document files keep their --- separators. Anchors and aliases are preserved, although their names are regenerated, for example &ref_0.

Before formatting, the tool validates your input. If the file contains a syntax error, nothing is rewritten, and you see the line and column to fix instead of a half-formatted result.

Why consistent YAML formatting matters

Indentation is part of YAML's syntax, so inconsistent spacing is more than a style issue. It is a common source of broken configuration. Uniform formatting makes mistakes easier to spot, keeps version-control diffs focused on real changes instead of whitespace, and lets teams review each other's changes without arguing over style.

When to format your YAML

  • Before committing

    Normalise a hand-edited file so the diff only shows real changes.

  • Cleaning up generated YAML

    Make output from scripts and templating tools readable.

  • Merging configs

    Sort keys on both versions so differences stand out.

  • Standardising a team style

    Agree on 2 or 4 spaces and apply it everywhere in seconds.

YAML Formatter FAQ

How do I format YAML online?

Paste your YAML or upload a .yaml or .yml file, choose your indentation and options, and the formatted result appears instantly. Copy it or download it as a file.

Does formatting remove my comments?

Reformat mode does, because it rewrites the YAML from its data and comments are not part of the data. The tool shows a note when this happens. Tidy whitespace mode keeps every comment while cleaning up spacing.

Will formatting change the meaning of my YAML?

No. Values, structure and order are preserved. Dates are kept as written, multi-document files keep their separators, and invalid YAML is never rewritten. Only the style changes, plus key order if you turn on Sort keys.

Is my YAML sent to a server?

No. Formatting runs entirely in your browser. Nothing you paste or upload leaves your device.

Should I use 2 or 4 spaces?

Both are valid, and two spaces is the most common convention in Kubernetes, GitHub Actions and Docker Compose files. Use whatever your team or tooling already follows, as long as it is consistent.

What does the Indent lists option do?

With it on, list items are indented under their parent key. With it off, the dashes line up with the key instead. Both are valid YAML, and the choice is purely a style preference.

What is the maximum file size?

Files up to 2 MB are supported, which is far larger than almost any configuration file.