Advertisement

YAML Formatter

Paste YAML with inconsistent indentation and normalize every nesting level to clean two-space steps. Trailing whitespace is trimmed and comments and blank lines are preserved, all locally in your browser.

YAML

Paste YAML with messy indentation below.

Advertisement

How the YAML formatter works

The tool reads the leading whitespace of every non-empty line, maps each distinct indent width to a nesting level, and re-emits the file with two spaces per level. Comments and blank lines pass through untouched, and trailing spaces are stripped from every line.

Why YAML indentation matters

YAML has no braces, so indentation is the syntax. Mixing two and four spaces, or tabs and spaces, breaks parsers with cryptic errors. Normalizing to one consistent width makes configs for Docker Compose, GitHub Actions and Kubernetes far less error prone.

YAML Formatter FAQs

Does it validate my YAML?
No. It only normalizes indentation and whitespace. Structural mistakes like a missing colon will still be there, so run the result through a YAML linter or your app parser before deploying.
What happens to tabs?
Tabs are converted to two spaces before normalization, since the YAML spec forbids tabs for indentation. If your file used tabs inconsistently, double check the nesting after formatting.
Are comments preserved?
Yes. Full-line comments keep their relative position and are re-indented with the surrounding block, so documented configs stay documented.
Can it convert JSON to YAML?
Not directly. Convert JSON to YAML with a dedicated converter first, then use this formatter to clean up the indentation of the result.
Why two spaces?
Two spaces is the most common YAML convention and the default in Prettier and most editor configs. If your team uses four spaces, replace the leading pairs after formatting.
Advertisement