YAML Syntax Reference

YAML 1.2 scalars, sequences, mappings, anchors and multi-document syntax.

Interactive YAML 1.2 syntax reference covering block and flow styles, scalar types, literal and folded blocks, anchors, aliases, tags, multi-document streams and the classic quoting gotchas.

What is the YAML Norway problem?

Under YAML 1.1, the bare token NO (a country code for Norway) parses as the boolean false, and YES/ON/OFF behave similarly. YAML 1.2's core schema fixes this by only treating true and false as booleans, but many parsers still default to 1.1, so quoting such values is safest.

A tour of YAML 1.2 syntax

YAML is a human-friendly data serialization language used for configuration in tools like Docker Compose, Kubernetes, GitHub Actions and CI pipelines. This reference covers the building blocks — scalars, sequences, mappings, anchors, tags and multi-document streams — alongside the quoting traps that catch almost everyone at least once.

How it works

Structure comes from indentation (spaces only, never tabs). A colon-space makes a mapping entry; a dash-space makes a sequence element:

service:
  name: web
  ports: [80, 443]
  env:
    - DEBUG=1
  base: &defaults
    retries: 3
  worker:
    <<: *defaults
    name: worker

Scalars can be plain, single-quoted (fully literal, only '' escapes a quote) or double-quoted (supports \n, \t and \uXXXX). The literal | and folded > block styles handle multi-line text. Anchors (&name) and aliases (*name) plus the merge key (<<:) let you reuse nodes.

Tips and notes

  • Use spaces for indentation; a single tab anywhere is a parse error.
  • Prefer the 1.2 core schema where only true/false are booleans.
  • Quote times like 22:22, ports, and leading-zero IDs to dodge base-60/octal parsing.
  • Separate multiple documents in one file with ---, and end optionally with ....