Languages
YAML Cheat Sheet — Syntax Reference with Examples
YAML is indentation-based and mostly simple, with a few rules that cause most of the bugs. This sheet covers the syntax used in Docker Compose, Kubernetes, GitHub Actions, and CI configs.
Put it into practice with the matching tool.
Convert YAML and JSON →Advertisement
Basics
key: valueA mapping entry — a space after the colon is requiredparent:
child: 1Nesting by indentation (spaces only, never tabs)# commentComment to the end of the line{ a: 1, b: 2 }Inline (flow) mapping---Start of a document; several can share one file...Optional end-of-document markerLists
- apple
- pearBlock list[apple, pear]Inline (flow) list- name: web
port: 80List of mappings — keys align after the dashkey: []Empty listScalars and types
n: 42 / f: 3.14Integer / floatok: trueBoolean (true / false)x: null / x: ~Null; an empty value is also nulld: 2026-10-29Parsed as a date by many YAML loadersv: "1.10"Quote to keep a string — unquoted 1.10 becomes 1.1country: "NO"Quote to avoid YAML 1.1 reading no/yes/on/off as booleansStrings and multi-line text
'single quotes'Literal; escape a quote by doubling it: ''"double \n quotes"Supports escapes like \n and \ttext: |Literal block — keeps line breakstext: >Folded block — line breaks become spaces|- / |+Strip / keep the final newlineurl: "http://a.com/#x"Quote values containing ": " or " #"Anchors and aliases
base: &defaults
retries: 3Define an anchor named defaultsjob: *defaultsReuse the anchored valuejob:
<<: *defaults
retries: 5Merge key: copy and override (not supported everywhere)