YAML Formatter

Paste untidy YAML and get it back with consistent indentation and one clean style.

Formatted in your browser. Your YAML is never uploaded. How we know

Reformat CtrlEnter

0 lines
or drop a .yaml or .yml file
YAML
 

Formatted YAML will appear here as you type.

Ln 1, Col 1 Spaces: 2 UTF-8
Processed in this tab

Processed in this tab

How to format YAML

Formatting here takes three steps, and nothing leaves your browser.

  1. Paste or open. Paste YAML into the left pane, use Open file for a .yaml or .yml file, or drop the file onto the pane.
  2. Pick an indent. Choose 2 or 4 spaces. The formatted YAML updates as you type.
  3. Take it with you. Copy the result, download it as a .yaml file, or make a share link.

The formatter reads your YAML into data and writes that data back in one consistent style. If the file doesn't parse, you get the line, the cause and the fix instead, the same as in the YAML validator.

What the formatter changes

Only the layout changes. Load the sample to see each of these on a real workflow file.

Indentation jobs: build:
Every level gets the indent you pick, 2 or 4 spaces, whatever mix the file had before.
Inline lists and maps branches: [main] env: {CI: "true"}
Written in block style, one key or item per line.
Needless quotes name: "deploy"
Removed where the text is unambiguous. Kept where removing them would change the type, as in "true" or "12".
Extra spaces run: npm test
Runs of spaces after a colon are reduced to one.
Blank lines
Empty lines between sections are removed.

What it keeps as written

A formatter must not change what a file means to the tool that reads it. Some YAML values are read differently by older parsers depending on whether they are quoted, so those are written back exactly the way you wrote them.

Key order b: 1 a: 2
Kept as written. Keys are never sorted.
yes, no, on, off become: yes label: "yes"
An unquoted yes stays unquoted and a quoted one stays quoted, so tools that read yes as a boolean, such as Ansible, see no change.
Port mappings and times - "22:22"
Values like 22:22 keep their quotes. Older YAML parsers read the unquoted form as a base-60 number.
Dates and special numbers released: 2026-09-24 limit: .inf
Written back exactly as they were.
Long lines description: a very long line…
Left alone. Nothing is folded or re-wrapped.
Multiple documents ---
Each document is formatted and kept, separated by ---.

What it removes

Because the file is rebuilt from its data, two things that aren't data don't survive. Check this list before you replace a file you maintain by hand.

Comments # like this
Removed. The formatter rebuilds the file from its data, and comments aren’t data. A note tells you when this happens.
Anchors and aliases &defaults *defaults
Written out as full copies. The data is the same, but the file is longer and the link between the copies is gone.

That makes this formatter a good fit for generated files, exported config and anything without comments. For a hand-written file full of comments, use a formatter that edits the text in place, such as Prettier.

More YAML and JSON tools

Every tool here runs in your browser, with the same editor, share links and plain-English errors.

Frequently asked questions

How do I format a YAML file?

Paste the YAML into the left pane or open the file. The formatted version appears on the right as you type. Pick 2 or 4 spaces of indent, then copy the result or download it. It runs in your browser, with nothing to install.

How many spaces should YAML be indented with?

Two is the most common choice and what most projects use. YAML accepts any number of spaces as long as keys of the same level line up, so 4 works too. It never accepts tabs. What matters most is using one width through the whole file, which is what this formatter does.

Does formatting change what my YAML means?

No. The file is parsed and written back, so the data is the same: same keys, same order, same values. Values that older parsers treat specially, like an unquoted yes or a quoted "22:22", keep their quoting. Aliases are written out as full copies, which is the same data in a longer form.

Why did my comments disappear?

This formatter reads the YAML into data and writes that data back, and comments are not part of the data. It shows a note whenever the input had comments. If you need them kept, use a formatter that edits the text in place, such as Prettier, and use this one for files without comments.

Can it fix invalid YAML?

No. A file has to parse before it can be formatted. If it doesn’t, you get the line and column of the first error with the cause and the fix, the same as in the validator. Correct that line and the formatted output appears.

Is my YAML uploaded anywhere?

No. Formatting runs in your browser tab, and the page never sends your YAML in any request. An automated test checks this on every build of the site.