elefcode
← All cheat sheets

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 required
parent: 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 marker

Lists

- apple - pearBlock list
[apple, pear]Inline (flow) list
- name: web port: 80List of mappings — keys align after the dash
key: []Empty list

Scalars and types

n: 42 / f: 3.14Integer / float
ok: trueBoolean (true / false)
x: null / x: ~Null; an empty value is also null
d: 2026-10-29Parsed as a date by many YAML loaders
v: "1.10"Quote to keep a string — unquoted 1.10 becomes 1.1
country: "NO"Quote to avoid YAML 1.1 reading no/yes/on/off as booleans

Strings and multi-line text

'single quotes'Literal; escape a quote by doubling it: ''
"double \n quotes"Supports escapes like \n and \t
text: |Literal block — keeps line breaks
text: >Folded block — line breaks become spaces
|- / |+Strip / keep the final newline
url: "http://a.com/#x"Quote values containing ": " or " #"

Anchors and aliases

base: &defaults retries: 3Define an anchor named defaults
job: *defaultsReuse the anchored value
job: <<: *defaults retries: 5Merge key: copy and override (not supported everywhere)

Related guides

More cheat sheets