Reading — step 1 of 5
Read
~1 min readYAML Basics
Indentation Rules
YAML uses indentation for structure. Critical rules:
- Spaces only, NO tabs (mixing breaks parsers).
- Indentation level = number of leading spaces.
- Children indented MORE than parent.
- Siblings at SAME indent level.
parent:
child1: value
child2:
nested: value
child3: value
Indent count is consistent within a block but flexible between blocks. Best practice: 2 spaces per level.
Common errors:
# BAD: tabs
parent:
child: value
# BAD: inconsistent
parent:
child1: value
child2: value # 1 extra space
# OK
parent:
child1: value
child2: value
Lists (sequences):
items:
- apple
- banana
- cherry
The - is a list marker; indentation tracks the parent.
Block list inside map:
fruits:
- apple
- banana
veggies:
- carrot
Two equivalent indentations:
items:
- apple # marker at parent's level (allowed)
- banana
items:
- apple # marker indented MORE (also allowed)
- banana
Both valid. Style varies; explicit indent is clearer.
Map of lists:
colors:
primary:
- red
- blue
- yellow
secondary:
- green
- orange
- purple
Mixed nesting:
people:
- name: Alice
age: 30
- name: Bob
age: 25
The - starts a list item that's a map.
Linters help (yamllint).
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…