YAMLYMLConfigurationDevOpsTutorial

Let's Learn YAML!

A beginner guide to .yaml and .yml files, covering syntax, common use cases, and a practical tutorial for writing clean configuration files.

Reza Zacky RamadhanJanuary 19, 20268 min read

What Is YAML?

YAML is a simple format for writing structured data. You will usually see it in configuration files, especially files with .yaml or .yml extensions.

You can think of YAML as a friendly way to describe data without too many brackets, commas, or quotes. It is popular because humans can read it quickly, and programs can parse it into objects, arrays, strings, numbers, and booleans.

For example:

yaml
name: Reza
role: Frontend Engineer
active: true
yearsOfExperience: 1

That small file describes four values:

  • name is a string
  • role is also a string
  • active is a boolean
  • yearsOfExperience is a number

.yml vs .yaml

Both extensions mean the same thing.

You might see:

text
config.yaml
text
config.yml

They both contain YAML. The .yaml extension is more descriptive, while .yml is shorter and my preference. In daily work, use whichever your project already uses.

Why Developers Use YAML

YAML is often used for configuration because it is easy to scan.

You will find YAML in places like:

  • GitHub Actions workflows
  • Docker Compose files
  • Kubernetes manifests
  • CI/CD pipeline settings
  • Static site config files
  • App environment config
  • API documentation tools like OpenAPI

Here is a small GitHub Actions example:

yaml
name: CI

on:
  push:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install dependencies
        run: npm install

      - name: Run tests
        run: npm test

Even if you do not know GitHub Actions yet, you can still guess the shape. The workflow has a name, it runs on push to main, then it runs a test job with several steps.

That readability is the main reason YAML is everywhere.

The Most Important Rule: Indentation Matters

YAML uses indentation to understand structure.

Compare these two examples:

Invalidflat-server.yml
server:
host: localhost
port: 3000
Validnested-server.yml
server:
  host: localhost
  port: 3000

In the valid version, host and port belong inside server.

Now host and port are not nested under server. Many tools will reject this because the structure is broken.

Use spaces for indentation. Two spaces is the most common style.

Avoid tabs. Tabs can make YAML parsers complain, and the error messages are rarely fun.

Key-Value Pairs

The most basic YAML syntax is a key followed by a value.

yaml
appName: Portfolio
environment: production
debug: false

The key is on the left. The value is on the right.

In JavaScript, this would look similar to:

javascript
const config = {
  appName: "Portfolio",
  environment: "production",
  debug: false,
};

YAML is basically giving you a cleaner way to write that data in a config file.

Strings

Most simple text values do not need quotes.

yaml
title: Basic YAML Guide
author: Reza

But quotes are useful when the value has special characters or might be misunderstood.

yaml
version: "1.0"
message: "Build: success"

Without quotes, some tools may read 1.0 as a number. With quotes, it stays text.

My simple rule: if the value feels like plain words, skip quotes. If the value looks like a version, URL, date, or command, quotes are safer.

Numbers and Booleans

YAML supports numbers:

yaml
port: 3000
timeout: 30
price: 19.99

It also supports booleans:

yaml
debug: true
cacheEnabled: false

Keep booleans lowercase. That is the style most tools expect.

Lists

Lists use a dash.

yaml
tags:
  - Frontend
  - Testing
  - DevOps

In JavaScript, that would become:

javascript
const config = {
  tags: ["Frontend", "Testing", "DevOps"],
};

Lists are common in YAML because config often has repeated items, like build steps, services, plugins, or allowed domains.

Nested Objects

You can nest data by indenting it.

yaml
database:
  host: localhost
  port: 5432
  credentials:
    username: admin
    password: secret

The structure is:

  • database contains host, port, and credentials
  • credentials contains username and password

This is where indentation becomes very important. Every child item must line up with its siblings.

Lists of Objects

A very common YAML pattern is a list where each item has multiple fields.

yaml
projects:
  - name: Portfolio
    stack: Next.js
    deployed: true

  - name: Quran Reader
    stack: Next.js
    deployed: true

Each - starts a new item. The fields under it belong to that item.

This pattern appears a lot in CI/CD:

yaml
steps:
  - name: Install dependencies
    run: npm install

  - name: Run tests
    run: npm test

  - name: Build app
    run: npm run build

Once you understand this pattern, many YAML files become much less scary.

Comments

Comments start with #.

yaml
# Runs the app in development mode
environment: development

# Change this to false in production
debug: true

Use comments to explain why something exists, not to repeat what the key already says.

This comment is not helpful:

yaml
# Port number
port: 3000

This one is better:

yaml
# Vercel expects this app to run on port 3000 locally
port: 3000

Multi-Line Strings

Sometimes you need a value that spans multiple lines.

Use | when you want to preserve line breaks:

yaml
releaseNotes: |
  Fixed login bug.
  Improved dashboard loading.
  Added better error messages.

Use > when you want YAML to fold the lines into one paragraph:

yaml
description: >
  This app helps developers learn YAML
  with simple examples and practical usage.

Most of the time, you will use | for scripts or long text where line breaks matter.

Environment Variables in YAML

YAML itself does not automatically understand environment variables. The tool reading the YAML decides what syntax is allowed.

For example, Docker Compose supports this:

yaml
services:
  web:
    image: my-app
    ports:
      - "${APP_PORT}:3000"

GitHub Actions uses a different style:

yaml
env:
  NODE_ENV: production
  API_URL: ${{ secrets.API_URL }}

Same YAML format, different tool rules.

That is an important mindset: YAML handles the structure, but each tool decides what the values mean.

A Small Tutorial: Create an App Config

Let us write a small YAML config for a web app.

Start with the app identity:

yaml
app:
  name: Reza Portfolio
  version: "1.0.0"
  environment: development

Add server settings:

yaml
server:
  host: localhost
  port: 3000

Add feature flags:

yaml
features:
  blog: true
  quranReader: true
  newsletter: false

Add allowed domains:

yaml
allowedDomains:
  - localhost
  - rezazr.vercel.app

Now combine everything:

yaml
app:
  name: Reza Portfolio
  version: "1.0.0"
  environment: development

server:
  host: localhost
  port: 3000

features:
  blog: true
  quranReader: true
  newsletter: false

allowedDomains:
  - localhost
  - rezazr.vercel.app

That is a real YAML file shape you could use in many projects.

Common Mistakes

Mixing Tabs and Spaces

Use spaces only.

Badtabs.yml
server:
	host: localhost
Goodspaces.yml
server:
  host: localhost

Forgetting Spaces After Colons

YAML expects a space after the colon in key-value pairs.

Badcompact.yml
name:Reza
Goodreadable.yml
name: Reza

Breaking List Indentation

Badbroken-step.yml
steps:
  - name: Install
  run: npm install
Goodaligned-step.yml
steps:
  - name: Install
    run: npm install

In the good version, run is aligned under name, so both belong to the same list item.

Leaving Risky Values Unquoted

When in doubt, quote values that look like versions, dates, or special strings.

Badguessed-types.yml
version: 1.0
date: 2026-05-29
command: npm run build
Goodexplicit-strings.yml
version: "1.0"
date: "2026-05-29"
command: "npm run build"

This keeps the parser from guessing the wrong type.

A Simple Checklist

Before you commit a YAML file, check these:

  • Did you use spaces, not tabs?
  • Are child values indented consistently?
  • Does every key-value pair have a space after :?
  • Are lists aligned correctly?
  • Did you quote versions, dates, and commands?
  • Did you validate the file with the tool that will read it?

Final Thoughts

YAML is not hard, but it is strict about whitespace. Once you understand indentation, key-value pairs, lists, and nested objects, you can read most .yml files without panic.

The best way to learn it is to open config files you already use, like GitHub Actions or Docker Compose, and read them from top to bottom. Ask yourself: what is a key, what is a value, what is a list, and what is nested inside what?

That habit turns YAML from "weird config syntax" into a language you can scan in a few seconds.

Tags:
#YAML#YML#Configuration#DevOps#Tutorial

Stay Updated

Get notified when I publish new articles about web development, frontend engineering, and more.

No spam, unsubscribe anytime.