YAML Formatter

Formatting runs in this browser. Your YAML is not uploaded.

Paste YAML with up to 1,000,000 characters and up to 100 documents. Formatting happens in this browser.

YAML is forgiving about syntax and unforgiving about indentation. A single-space slip can silently turn a key into a list item, and mixed indentation makes reviews painful. This formatter parses your input with the js-yaml engine (YAML 1.2 core schema) directly in your browser, then re-emits it with the indentation, collection style, quoting, key order and line width you choose, so configs diff cleanly in version control and stay readable across contributors.

How to format YAML

  1. 1

    Paste YAML

    Up to 1,000,000 characters and up to 100 documents in one stream. Nothing is uploaded: parsing runs in your browser.

  2. 2

    Pick options

    Indent width, block or flow style, quoting, key sorting and line width.

  3. 3

    Format

    The tool rebuilds each document with canonical spacing and your chosen style.

  4. 4

    Copy and commit

    The output is structurally identical YAML, ready to paste back into your config.

Before and after

Messy input:

server:
  port:   8080
  hosts: ["api.example.com",  "api2.example.com"]
  timeout:  30
  debug: true

Formatted (2 spaces, block style):

server:
  port: 8080
  hosts:
    - api.example.com
    - api2.example.com
  timeout: 30
  debug: true

Formatting options

Option Values Default
Indent width 2, 4 2
Collection style Block, flow Block
Quoting Minimal, double, single Minimal
Sort keys Original, alphabetical Original
Line width 80, 120, unlimited 120

Quoting rules

Minimal quoting is usually what you want: strings stay unquoted unless leaving them bare would be unsafe. The formatter adds quotes automatically for:

  • Legacy booleans as strings: yes, no, on, off, y, n. YAML 1.2 already reads them as strings, but many parsers still follow YAML 1.1, where an unquoted no becomes false. The formatter always quotes them in the output, so the famous Norway bug (NO read as false in a country list) cannot bite whoever consumes your file.
  • Numbers as strings: '007', '3.14'. Unquoted they would be parsed as integers or floats.
  • Strings containing characters like :, #, [, { or starting whitespace, where bare output would change the structure.

Cleanups you get on every run

  • Trailing whitespace. Stripped.
  • Mixed or irregular indentation. Normalised to your chosen indent width.
  • Blank lines inside collections. Removed.
  • Tabs in indentation. YAML forbids them; the parser rejects the input with a clear error that points at the line, so you can fix it instead of shipping a file other parsers will refuse.

Comments, anchors and merge keys

Formatting normalises the document model, which has limits worth knowing before you commit:

  • Comments are removed. The parser resolves the document to data, so # comments do not survive formatting. Keep a copy if your comments matter.
  • Anchors and aliases are resolved. Nodes shared through an alias stay shared, but they are re-emitted with generated names such as &ref_0; original anchor names are not kept.
  • Merge keys (<<:) are resolved into plain mappings with the merged values in place.

Multi-document streams

Streams with several documents are supported: each document is formatted independently and re-joined with the --- separator, up to 100 documents per run.

Frequently Asked Questions

Structure and values stay identical: only the rendering (indentation, quoting, flow vs block, key order if you enable sorting) changes. Two things are not preserved, by design: comments are removed and anchor names are regenerated.

When a bare string would be parsed as something else, quoting is required for safety. Common cases: keys or values that are just digits, strings containing : or #, and legacy booleans like yes and no that YAML 1.1 parsers would read as true/false.

No. The style option applies to the whole document: block expands every collection onto its own lines, flow renders collections inline. Format twice with different options if you need to compare.

No. Parsing and formatting run in your browser with the bundled js-yaml engine. Your YAML is not sent through the server, not stored, and never added to the page address; it only lives in this browser session so the multi-step view can show your result.

Related Tools