What YAML is
- A human-friendly data serialization language.
- Usually used for configuration, infrastructure, CI pipelines, manifests, and content files.
- Capable of representing objects/maps, arrays/lists, strings, numbers, booleans, nulls, and more.
This tutorial is designed to teach the full practical YAML syntax: indentation, scalars, lists, maps, multiline strings, anchors, aliases, merge keys, tags, multi-document files, and the mistakes that break production configs.
app:
name: yaml-atlas
enabled: true
ports:
- 8080
- 8443
database:
host: db.local
retries: 3
How YAML is structured, how each scalar style behaves, and how to read and write configs confidently.
No shallow “YAML is just indentation” treatment. This covers the weird parts too, including quoting rules, booleans, anchors, merge behavior, and multiline traps.
Use YAML when humans need to read and edit structured data. Reach for JSON, TOML, or another format when machine strictness matters more than friendliness.
Start with the mental model first. YAML is a way to represent nested data structures using indentation and a few compact syntax forms.
If you understand those three pieces, the rest is mostly syntax details and edge cases.
# Mapping at the top level
app:
name: YAML Atlas
version: 1.0
debug: true
maintainers:
- Athy
- Oracle
These are the pieces you will use most often.
YAML uses spaces to show nesting. Use spaces only. Do not use tabs.
server:
host: localhost
port: 8080
ssl:
enabled: true
server:
host: localhost
port: 8080
A mapping is a set of key/value pairs. Think JSON object or dictionary.
database:
host: db.example.com
port: 5432
username: app_user
password: secret
{ name: Sam, role: admin, active: true }Inline syntax is valid, but block style is usually easier to read.
A sequence is an ordered list. Each item starts with a dash and a space.
features:
- auth
- billing
- analytics
users:
- name: Athy
role: owner
- name: Oracle
role: assistant
A list item can itself contain nested keys, but those nested keys must line up under that list item.
A scalar is a single value like text, a number, true/false, or null.
plain_text: hello
integer: 42
float: 3.14
boolean_true: true
boolean_false: false
empty_value: null
also_empty: ~
string_number: "42"
string_boolean: "true"
date_like: "2026-05-13"
YAML has several string styles. This is one of the most important parts to learn well.
title: Hello worldNo quotes needed if the text is simple and unambiguous.
title: 'Literal text'Useful when you want backslashes treated literally.
title: "Line
Break"Supports escape sequences like
and .
message: |
line one
line two
line three
| keeps line breaks.
message: >
line one
line two
line three
> folds most line breaks into spaces.
keep_trailing_newline: |
hello
strip_trailing_newline: |-
hello
keep_extra_newlines: |+
hello
Comments start with #.
# top-level comment
app:
name: yaml-atlas # inline comment
debug: false
These features matter once you are writing larger config files or DRYing up repeated structures.
Anchors let you name a block. Aliases let you reuse it.
defaults: &defaults
retries: 3
timeout: 30
log_level: info
service_a:
<<: *defaults
host: a.example.com
service_b:
<<: *defaults
host: b.example.com
timeout: 60
&defaults defines an anchor.*defaults references it.<<: is the merge key commonly used to merge mappings.YAML supports tags that explicitly describe the type of a value.
port: !!int "8080"
enabled: !!bool "true"
name: !!str 123
You will not use tags every day, but they help when parser inference is not giving you what you want.
YAML can contain multiple documents separated by ---. Some tools, like Kubernetes, rely on this heavily.
---
kind: ConfigMap
metadata:
name: app-config
---
kind: Service
metadata:
name: app-service
... can explicitly end a document, though many files omit it.
YAML also supports inline “flow” style similar to JSON.
user: { name: Athy, role: owner }ports: [80, 443, 8080]This is valid, but use it sparingly. Block style is usually easier to maintain.
This is where YAML becomes less abstract and more useful.
Many parsers reject them outright.
yes, on, or date-like values may be interpreted unexpectedly depending on the parser.
One extra space can move data into a different object.
Plain strings containing a colon can need quoting.
| and > behave differently; do not treat them as interchangeable.
Anchors are useful, but overusing them can make a file harder to read than duplication would.
YAML is friendlier when your editor and linter catch mistakes early.
Add schema support, validation, autocomplete, and better editing ergonomics.
Use it to catch indentation problems, style issues, and common syntax errors.
For formats like Kubernetes or GitHub Actions, schema-aware tooling is much better than syntax checks alone.
yamllint your-file.yaml
docker compose config kubectl apply --dry-run=client -f manifest.yaml
# Example: map YAML files to their schema in your editor config
A compact reference you can come back to later.
key: value → mapping entry- item → list itemhello'hello'"hello"|>true / falsenull / ~&name → anchor*name → alias<<: *name → merge mapping--- starts a document... can end oneIf a value could be misunderstood by a parser or a human, quote it and keep the structure boring.
At this point you should be able to read and write most YAML files you will meet in the wild: CI configs, Docker Compose, Kubernetes manifests, app settings, content metadata, and templated config with anchors.
The remaining challenge is not memorizing more syntax. It is learning the parser and conventions of the tool you are working with.