YAML Indentation
Spaces, tabs, common errors, and how to fix indentation fast.
The one rule
YAML uses spaces to show nesting. Tabs are not allowed for indentation. Mixing spaces and tabs is the most common cause of a YAML parse error.
How many spaces?
The YAML spec does not mandate a number, but the convention is 2 spaces per indentation level. Four spaces also works as long as every level in the same file uses the same step.
# 2-space indentation (recommended)
config:
debug: true
services:
- api
- db
# 4-space indentation (valid, but be consistent)
config:
debug: true
services:
- api
- db
Common indentation errors
- Tab characters copied from a terminal or editor configured for tabs.
- Inconsistent depth — one list item indented 2 spaces, the next 3.
- Indenting the dash differently from the list item content.
# Bad: mixing depths
items:
- name: api
port: 8080 # one space too many
# Bad: tab before "debug"
config:
debug: true
How to fix YAML indentation
- Open the YAML formatter.
- Paste your messy YAML into the input box.
- Copy the output, which is re-indented with consistent 2-space spacing.
For structural problems, run the same text through the YAML validator to see the exact line number of the error.
Why does indentation matter in YAML?
Unlike JSON, YAML has no braces or closing tags. The structure is entirely defined by indentation. If the indentation is wrong, the parser cannot tell what belongs to what.
Related guides
- YAML format example — a readable annotated sample.
- YAML validation guide — common errors and fixes.
- What is YAML? — a plain-language introduction.