Skip to content

YAML syntax error: invalid indentation

Quick summary

Your YAML file has a syntax error — inconsistent or incorrect indentation prevents parsing.

Why this happens

  • Tabs are used instead of spaces for indentation (YAML requires spaces)

  • Indentation is inconsistent — items at the same level have different indentation

  • A mapping key is missing its value or a list item is missing the dash prefix

Minimal example

✗ Broken code
services:
  web:
    ports:
      - '80:80'
	db: # tab character — YAML error
    ports:
      - '5432:5432'
✓ Fixed code
services:
  web:
    ports:
      - '80:80'
  db: # spaces — valid YAML
    ports:
      - '5432:5432'

Replacing the tab character with spaces makes the YAML valid and allows it to be parsed correctly.

How to diagnose

  • Use a YAML linter or validator to identify the exact line and column of the error

  • Check for tab characters and replace them with spaces

  • Verify that items at the same nesting level have consistent indentation

How to fix

  • Replace tabs with spaces and ensure consistent indentation throughout the file

  • Fix the indentation of misaligned items to match their nesting level

  • Add missing values or list item dashes as required by YAML syntax

How to prevent

  • Use a YAML linter in the editor and CI pipeline to catch syntax errors early

  • Configure the editor to use spaces for YAML files and enforce consistent indentation

Related Resources

Related Glossary

Related Lessons

← Back to language