YAML Formatter
Clean up messy YAML in one click. The default mode formats with Prettier, the formatter many teams use in their editors: indentation, spacing and quotes become consistent and comments stay where they are. The normalise mode rewrites the data in block style, expanding {…} and […] forms, quoting risky values and optionally sorting keys.
- Runs in your browser
- No sign-up
- Free to use
How to use YAML Formatter
- Paste YAML or open a file.
- Choose indentation, quote style and mode.
- Click Format.
- Copy or download the formatted YAML.
YAML Formatter features
Comments kept
Prettier formatting preserves comments and document layout.
Normalise mode
Block style, sorted keys and consistent quoting from the parsed data.
Consistent style
2 or 4 spaces, single or double quotes.
Safe values
Normalise mode quotes values such as NO or yes.
Multi-document
Files with --- separators.
Error positions
Invalid YAML reported with line and column.
When to use YAML Formatter
- Tidying a hand-edited Docker Compose or Kubernetes file.
- Making YAML diffs smaller by using one style across a team.
- Expanding compact flow syntax into readable block style.
- Sorting keys for easier comparison of configuration files.
YAML Formatter FAQ
Which mode should I use?
Use Format for files people maintain, because it keeps comments. Use Normalise when you want a canonical form from the data itself, for example to compare two files.
Why are comments lost in normalise mode?
Normalising parses the YAML into data and writes it again; comments are not part of the data. Format mode works on the document and keeps them.
Does formatting change values?
No. Format mode only changes layout. Normalise mode can change representation, such as quoting style, but not the parsed values.
Is it the same as Prettier in my editor?
Yes, it uses Prettier’s YAML plugin, so results match an editor using Prettier with the same options.
What about anchors and aliases?
Format mode keeps them. Normalise mode expands them into the referenced data.
Is my YAML uploaded?
No. Formatting runs in your browser.
Formatting YAML without losing information
YAML files grow messy as several people edit them: inconsistent indentation, mixed quote styles, flow collections next to block lists, stray spaces after colons. None of this changes the data, but it makes files harder to read and diffs noisier. A formatter applies one consistent style automatically.
The default mode uses Prettier’s YAML formatter, the same one used by editor integrations and pre-commit hooks. It parses the document into a syntax tree that includes comments, so comments, blank lines between sections, anchors and document separators are preserved while indentation and spacing are made consistent.
The normalise mode takes a different approach. It parses the YAML into data with js-yaml and writes it back out, which produces a canonical form: every mapping and list in block style, keys optionally sorted, strings quoted consistently, and values that YAML 1.1 tools would misread, such as NO or on, quoted for safety. Because it works on data, comments are not kept and anchors are expanded.
Both modes check the input first. If the YAML is invalid, the error is reported with its line and column and the editor marks the line, so formatting never hides a problem. Files with several documents separated by --- are handled in both modes.
Indentation of two spaces is the most common convention, used by Kubernetes, GitHub Actions and Docker documentation; four spaces is sometimes preferred for deeply nested files. Quote style affects only strings that need quoting.