YAML Formatter

Normalise YAML indentation and trailing whitespace.

  • Runs locally in your browser
  • No upload required

Try it

Paste YAML. Indentation is normalised in your browser; nothing is uploaded.

Formatted YAML
a: b: 1 c: 2
Lines
3
a:
  b: 1
  c: 2

Supported formats

Input
text, number
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Normalised 4 line(s) of YAML at 2-space depth.

How it works

  • Rejected tab indentation, which YAML forbids.
  • Mapped the document's existing indent unit onto the chosen width.
  • Removed trailing whitespace and preserved block-scalar content relative to its key.
  • Keys, values and comments are preserved; only indentation and trailing spaces change.
  • Output is 3 line(s); formatting it again changes nothing.

Methodology

  1. Check every line for tab indentation and reject it with a line/column.
  2. Derive the document's indent unit from its existing leading spaces.
  3. Re-emit each line at a level-based indent, preserving block-scalar content relative to its key.

Usage

  1. Paste or type a YAML document.
  2. Choose a 2- or 4-space indent.
  3. Run the formatter and copy the normalised result.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Mapping indentation

jsonSelect to copy
{
  "text": "a:\n    b: 1\n    c: 2\n",
  "indentSize": 2
}

Sequence under a key

jsonSelect to copy
{
  "text": "items:\n  - one\n  - two\n",
  "indentSize": 4
}

Block scalar preserved

jsonSelect to copy
{
  "text": "text: |\n  line one\n  line two\n",
  "indentSize": 2
}

Limitations

Indentation is structure in YAML

YAML uses indentation instead of braces, so a formatter must preserve relative depth. This tool normalises the width of indentation without changing the nesting it represents.

Frequently asked questions

Will my block scalar content change?
No. Block scalar bodies keep their content and their indentation relative to the key line is preserved.
Why was my YAML rejected?
The only structural error this formatter reports is tab indentation, which the YAML specification forbids.
Is my YAML uploaded?
No. The document is processed entirely in your browser.

Sources

  1. YAML Ain't Markup Language (YAML) 1.2.2 Specification — YAML.org
  2. MDN Web Docs — YAML — MDN