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/falseare 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....