What is YAML? Complete Beginner's Guide []

YAML (YAML Ain't Markup Language) is a human-readable data serialization language used for configuration files. This YAML tutorial covers everything beginners need to know: it uses indentation instead of brackets, supports comments, and is commonly used in Docker, Kubernetes, Ansible, and CI/CD pipelines like GitHub Actions. YAML 1.2 is the current version and is a superset of JSON. See how YAML compares to JSON in our YAML vs JSON comparison.

What Does YAML Stand For?

YAML stands for "YAML Ain't Markup Language"—a recursive acronym. Originally, it meant "Yet Another Markup Language," but the name was changed to emphasize that YAML is for data serialization, not document markup like HTML or XML.

YAML was created in 2001 by Clark Evans, along with Ingy döt Net and Oren Ben-Kiki. The current stable version is YAML 1.2.2, released in October 2021. A key milestone was YAML 1.2 (2009), which made YAML a superset of JSON—meaning any valid JSON file is also valid YAML.

Key fact: The recursive acronym "YAML Ain't Markup Language" reflects the design philosophy that YAML is about data representation, not document structure.

Is YAML a Programming Language?

No, YAML is not a programming language. It's a data serialization language used to represent structured data in a human-readable text format. YAML cannot execute logic, perform calculations, or run programs—it only stores and transmits data.

Think of YAML as a configuration format, similar to JSON or XML, but easier for humans to read and write. It's used to describe data that programs read, not to write the programs themselves. Need to convert between formats? See our Python or JavaScript conversion guides.

YAML vs Programming Languages

Feature YAML Programming Languages
Purpose Data storage/configuration Execute instructions
Can run logic? No Yes
Variables? No (only data) Yes
Loops/conditions? No Yes

What is YAML Used For?

YAML is used wherever you need human-readable configuration files. Here are the most common use cases:

  • Configuration files – Docker Compose, Kubernetes manifests, Ansible playbooks, and many applications use YAML for their settings.
  • CI/CD pipelines – GitHub Actions, GitLab CI, CircleCI, Azure Pipelines, and Jenkins use YAML to define build and deployment workflows.
  • Infrastructure as Code (IaC) – Tools like Ansible, AWS CloudFormation, and Kubernetes use YAML to define infrastructure resources.
  • API specifications – OpenAPI/Swagger definitions are commonly written in YAML for describing REST APIs.
  • Application settings – Many frameworks (Spring Boot, Ruby on Rails, etc.) use YAML for application configuration.
  • Data serialization – YAML can store and transfer structured data between applications and programming languages.

YAML Syntax Basics

YAML syntax is designed to be simple and readable. Here are the fundamental building blocks:

Key-Value Pairs

The basic unit of YAML is a key-value pair, separated by a colon and space:

name: John Doe
age: 30
email: [email protected]

Lists (Sequences)

Lists use a hyphen followed by a space:

fruits:
  - apple
  - banana
  - orange

Nested Objects (Mappings)

Use indentation (2 spaces recommended) to create nested structures:

person:
  name: Jane Smith
  address:
    street: 123 Main St
    city: New York
    country: USA

Comments

Comments start with a hash symbol (#):

# This is a comment
name: value  # Inline comment

Multi-line Strings

Use | for literal blocks (preserves newlines) or > for folded blocks:

# Literal block (preserves newlines)
description: |
  This is a long description
  that spans multiple lines.
  Each line break is preserved.

# Folded block (joins into one line)
summary: >
  This text will be
  joined into a single
  line with spaces.
Important: YAML uses spaces only for indentation—tabs are forbidden. Inconsistent indentation is the most common source of YAML errors.

YAML Example

Here's a complete, real-world YAML example—a Docker Compose configuration file:

# Docker Compose configuration
version: "3.8"

services:
  # Web application service
  web:
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./html:/usr/share/nginx/html
    environment:
      - NODE_ENV=production
    depends_on:
      - api
    restart: always

  # API backend service
  api:
    build: ./api
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgres://user:pass@db:5432/mydb
      SECRET_KEY: my-secret-key
    depends_on:
      - db

  # Database service
  db:
    image: postgres:14
    volumes:
      - db_data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb

volumes:
  db_data:

This example demonstrates key-value pairs, lists, nested objects, comments, and environment variables—all common patterns in YAML configuration files.

Need to convert YAML to JSON?

Use our free online converter to instantly transform YAML to JSON or vice versa.

Open Converter Tool →

Is YAML Human-Readable?

Yes, YAML is designed to be human-readable. This is one of its primary design goals. YAML uses indentation (like Python) instead of brackets and braces, making it easier to read and write than JSON or XML.

Compare the same data in YAML vs JSON:

YAML JSON
name: John
age: 30
skills:
  - Python
  - JavaScript
{"name":"John",
"age":30,
"skills":["Python",
"JavaScript"]}

However, the whitespace sensitivity that makes YAML readable can also cause errors if you're not careful with indentation. This is the main trade-off for readability.

Is YAML Easy to Learn?

Yes, YAML is easy to learn. Basic syntax can be understood in about 30 minutes, and proficiency takes roughly 2-4 hours of practice. The main challenge is getting comfortable with indentation rules—YAML uses spaces only (no tabs)—but the simple structure makes it very beginner-friendly.

Compared to JSON or XML, YAML has fewer special characters to memorize. Once you understand key-value pairs, lists, and nesting through indentation, you can read and write most YAML files. Advanced features like anchors and aliases might take a few more hours to master.

Learning timeline: 30 minutes for basics, 2-4 hours for proficiency, a few more hours for advanced features like anchors, aliases, and multi-document files.

What are the Disadvantages of YAML?

While YAML is popular and useful, it has some notable disadvantages:

  • Whitespace sensitivity – Indentation errors are easy to make and hard to debug. A single extra or missing space can break your entire file.
  • Slower parsing – YAML is slower to parse than JSON because of its more complex syntax and type inference.
  • No strong typing – YAML infers types from values, which can lead to unexpected behavior (e.g., "yes" becoming a boolean).
  • Inconsistent implementations – Different YAML parsers may handle edge cases differently, leading to portability issues.
  • Complex for deep nesting – Very deeply nested structures become hard to read and maintain.
  • Security concerns – Some YAML parsers execute arbitrary code during parsing (e.g., Python's unsafe yaml.load). Always use safe loaders.
Tip: Use a YAML validator or linter to catch indentation and syntax errors before they cause problems in production.

YAML in Docker and Kubernetes

YAML is the primary configuration format for both Docker Compose and Kubernetes. Understanding YAML is essential for working with modern container orchestration.

Docker Compose

Docker Compose uses docker-compose.yml files to define multi-container applications. You specify services, networks, volumes, and their configurations in a readable YAML format.

Kubernetes

Kubernetes uses YAML manifests for all cluster resources: Deployments, Services, ConfigMaps, Secrets, and more. A typical Kubernetes deployment might look like:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: my-app:1.0
        ports:
        - containerPort: 8080

Frequently Asked Questions

What does YAML stand for?

YAML stands for "YAML Ain't Markup Language"—a recursive acronym. Originally it meant "Yet Another Markup Language," but was changed to emphasize that YAML is for data serialization, not document markup. It was created in 2001 by Clark Evans.

Is YAML a programming language?

No, YAML is not a programming language. It's a data serialization language used to represent structured data in text format. YAML cannot execute logic or run programs—it only stores and transmits data. Think of it as a configuration format, not a coding language.

Is YAML easy to learn?

Yes, YAML is easy to learn. Basic syntax can be understood in 30 minutes, and proficiency takes about 2-4 hours of practice. The main challenge is getting comfortable with indentation rules (spaces only, no tabs), but the simple structure makes it beginner-friendly.

Is YAML used in Docker?

Yes, YAML is the primary configuration format for Docker Compose. Docker Compose uses docker-compose.yml files to define multi-container applications, specifying services, networks, volumes, and their configurations in a readable YAML format.

What does |+ mean in YAML?

The |+ in YAML is a literal block indicator with a "keep" chomping indicator. The pipe (|) preserves newlines in the text, and the plus (+) keeps all trailing newlines. Use |- to strip the final newline.

Is YAML replacing JSON?

No, YAML is not replacing JSON. They serve different purposes—JSON dominates API data exchange due to its speed and simplicity, while YAML is preferred for configuration files due to its readability and comment support. Both continue to be widely used.

Is YAML written in Python?

No, YAML is not written in Python—YAML is a data format specification, not a program. However, Python has excellent YAML support via the PyYAML library. YAML parsers exist for virtually every programming language.

How long does it take to learn YAML?

Basic YAML syntax takes about 30 minutes to learn. To become comfortable with common patterns and avoid indentation pitfalls, expect 2-4 hours of practice. Advanced features like anchors and aliases might take another few hours to master.

Is Docker Compose YAML?

Yes, Docker Compose uses YAML files (docker-compose.yml) to define and configure multi-container Docker applications. The YAML format allows you to specify services, networks, volumes, environment variables, and dependencies in a human-readable way.

Is YAML built into Python?

No, YAML is not built into Python's standard library. You need to install a third-party library like PyYAML (pip install pyyaml) to parse and generate YAML in Python. PyYAML is the most popular choice and supports YAML 1.1.

Is YAML a coding language?

No, YAML is not a coding language. It's a data serialization format used to store and transfer structured data. Unlike programming languages, YAML cannot execute logic, perform calculations, or run programs—it only describes data structures.