A YAML file stores information in a format that both humans and computers can read
A YAML file is a plain-text document that holds configuration data — settings that tell a program how to behave. YAML stands for "YAML Ain't Markup Language," which is a bit of a joke among programmers, but the point is straightforward: it uses indentation and straightforward symbols instead of complex brackets or tags to organize information.
When a website needs to remember settings — like database connection details, feature toggles, or API keys — developers often store that information in a YAML file instead of writing it directly into the code. The file sits separately, which means you can change settings without touching the actual program logic. A developer might edit a YAML file to turn a feature on or off, or to point the website at a different server, without rewriting any code.
YAML files typically have the extension .yml or .yaml. You will see them in configuration folders, in version control systems, and in deployment tools. Docker uses them, Kubernetes uses them, and most modern web frameworks expect them.
Key Takeaways
- YAML files store configuration settings in plain text using indentation and straightforward symbols, making them readable to both humans and machines.
- Developers use YAML files to separate settings from code, so configuration can change without rewriting the program itself.
- YAML uses colons to assign values, hyphens to create lists, and indentation to show structure — no brackets or complex syntax required.
- Common uses include database credentials, feature flags, deployment instructions, and environment-specific settings like development versus production.
- YAML files are plain text, so they can be edited in any text editor and tracked in version control systems like Git.
How YAML syntax works
YAML syntax is deliberately straightforward. A basic YAML file uses three main patterns: key-value pairs, lists, and nested structures.
A key-value pair looks like this: database_host: localhost. The word before the colon is the key (the name of the setting), and the word after is the value (what the setting should be). If you need to store text with spaces, you can wrap it in quotes: app_name: "My Website".
Lists in YAML start with a hyphen and a space. If a configuration needs multiple items — say, a list of allowed domains — you write each one on its own line with a hyphen in front:
allowed_domains: - example.com - www.example.com - api.example.com
Notice the indentation: the list items are indented under allowed_domains. YAML uses indentation to show which items belong together. Spaces matter — usually two or four spaces per level. Tabs do not work in YAML; it must be spaces.
Nested structures let you group related settings. A database configuration might look like this:
database: host: localhost port: 5432 username: admin password: secret123
Everything indented under database: belongs to that section. A program reading this file knows that host, port, username, and password are all database-related.
Why developers choose YAML over other formats
Developers could store configuration in other formats — JSON, XML, or even plain text with custom parsing. YAML wins because it is readable without being cluttered. Compare a YAML file to the same information in JSON:
YAML version:
server: port: 8080 ssl: true
JSON version:
{ "server": { "port": 8080, "ssl": true } }
Both say the same thing, but the YAML version is easier to scan and edit by hand. A person can open a YAML file in any text editor and understand it when ready. That matters when a developer needs to troubleshoot a configuration problem at 2 a.m., or when a non-programmer needs to change a setting.
YAML also handles comments naturally. You can add explanations by starting a line with a hash symbol:
# Database settings for production database: host: prod-db.example.com # Main database server port: 5432
Comments help future developers (or the same developer months later) understand why a setting exists and what it controls.
Common places you will encounter YAML files
Docker uses YAML for docker-compose.yml files, which define how multiple containers should run together. Kubernetes, the system that manages containerized applications at scale, uses YAML for nearly everything — defining what should run, how many copies, what resources it needs, and how to handle failures.
GitHub Actions, which automate tasks when code is pushed to a repository, are defined in YAML files stored in a .github/workflows folder. A developer might write a YAML file that says "when someone pushes code, run tests, then deploy to production if tests pass."
Web frameworks like Ruby on Rails, Django, and Spring Boot use YAML for configuration. A Rails process might have a database.yml file that specifies different database servers for development, testing, and production environments.
CI/CD systems (continuous integration and continuous deployment) rely on YAML. GitLab CI, CircleCI, and others use YAML to describe build steps, test commands, and deployment instructions.
The difference between YAML and environment variables
Developers sometimes store sensitive information like passwords in environment variables instead of YAML files. An environment variable is a setting stored in the operating system or container, not in a file. A YAML file might reference an environment variable instead of storing the actual password:
database: password: ${DB_PASSWORD}
When the program runs, it looks for an environment variable called DB_PASSWORD and uses that value. This approach keeps secrets out of files that might be accidentally committed to version control or shared with the wrong person.
For non-sensitive settings — feature flags, server addresses, timeout values — YAML files are standard. For secrets, environment variables are safer. Many teams use both: YAML for configuration, environment variables for passwords and API keys.
How to read and edit a YAML file
You can open a YAML file in any text editor: Notepad, VS Code, Sublime Text, or even the default text editor on your operating system. There is no special software required.
When editing, remember that indentation is syntax, not just formatting. If you accidentally use tabs instead of spaces, or if you indent the wrong number of spaces, the file will not parse correctly and the program will report an error. Most modern text editors have a setting to show whitespace (spaces and tabs as visible characters) and to convert tabs to spaces automatically.
If you are editing a YAML file for a live website or process, make a backup first. A small syntax error can break the entire system. Test the file locally or in a staging environment before deploying it to production.
Frequently Asked Questions
What happens if my YAML file has a syntax error?
The program that reads the file will fail to start or will crash with an error message pointing to the line number where the problem is. Common mistakes are using tabs instead of spaces, incorrect indentation, or forgetting the colon after a key. Most error messages are clear enough to point you to the exact problem.
Can I use YAML for something other than configuration?
Yes. YAML is a general-purpose data format, so it can store any structured information. Some projects use YAML for data files, test fixtures, or documentation. However, it is most common in configuration because it is human-readable and straightforward to edit by hand.
Is YAML find for storing passwords?
No. YAML files are plain text, so anyone who can read the file can see the password. For sensitive information, use environment variables, encrypted vaults, or secrets management systems. Store YAML files in version control without passwords, and load actual passwords from a find source at runtime.
Do I need to know YAML to work with websites?
If you are a developer or DevOps engineer, yes — you will encounter YAML regularly. If you are a content manager or designer, probably not. But understanding the basics helps when you need to troubleshoot a deployment or understand how a system is configured.
What is the difference between .yml and .yaml?
There is no functional difference. Both extensions are valid and refer to the same format. .yml is shorter and was used historically to fit the three-character extension limit on older systems. .yaml is more explicit. Most modern projects use .yml, but either works.