YAML Formatter & Beautifier

Format and beautify YAML with consistent indentation

What is YAML Formatting?

YAML formatting means taking YAML data — often with mixed indentation, inconsistent spacing, or pasted from different sources — and normalizing it into a clean, readable structure with uniform indent levels. Unlike JSON, where whitespace is cosmetic, YAML uses indentation to define its structure. A YAML formatter re-parses the data and re-serializes it with consistent spacing, making it easier to read, review in pull requests, and maintain over time.

Messy YAML is more than an aesthetic problem. Inconsistent indentation causes subtle bugs: a key that looks nested under one parent might actually belong to another if the indent is off by a single space. Running YAML through a formatter catches these structural issues by producing output where the visual layout matches the logical structure.

How to Format YAML

  1. Paste your YAML into the input area — a Kubernetes manifest, Docker Compose file, CI pipeline config, or any YAML document.
  2. Choose your preferred indentation in settings (2 spaces or 4 spaces).
  3. Click “Format” or press Ctrl+Enter.
  4. Copy the formatted result with the “Copy” button or Ctrl+Shift+C.

The formatter parses your YAML into a data structure and re-serializes it with clean, uniform indentation. Optionally enable “Sort keys” to alphabetize object keys at every level — useful for keeping configuration files deterministic and diff-friendly.

Compact Mode: Strip Comments and Blank Lines

The Compact button does the opposite of beautifying: it removes clutter without re-serializing your document. Click it to strip every full-line and inline # comment, collapse runs of blank lines into a single separator, and trim trailing whitespace — while leaving your existing indentation and key order untouched.

This is the right choice when you want a smaller, noise-free config to paste into a ticket, a chat message, or a kubectl apply -f - command, but you don’t want the formatter to rewrite the whole file. Where Format rebuilds the document from a parsed data structure (and therefore drops comments as a side effect), Compact is a lightweight cleanup that keeps the file recognizably yours.

Common YAML Formatting Problems

Mixed Indentation from Copy-Paste

Copying YAML snippets from documentation, Stack Overflow, or different files often produces a document with mixed 2-space and 4-space indentation. This is syntactically valid (YAML allows any consistent indent per level), but it makes the file hard to read and error-prone to edit. The formatter normalizes everything to your chosen indent size.

Tabs Mixed with Spaces

YAML forbids tab characters for indentation — this is the single most common YAML error. Tabs can sneak in from editors configured for other languages or from pasting terminal output. The formatter eliminates this by re-serializing with spaces only.

Deep Nesting with Inconsistent Levels

Kubernetes manifests and Helm charts routinely nest 5-8 levels deep. When different contributors use different indent widths at different levels, the result is a file that’s technically valid but visually chaotic:

spec:
  template:
      spec:
        containers:
              - name: app
                image: app:1.0

After formatting with 2-space indent:

spec:
  template:
    spec:
      containers:
        - name: app
          image: app:1.0

Flow Style Mixed with Block Style

YAML supports both block style (indented, multi-line) and flow style (inline, JSON-like). Mixing the two in a single file is valid but hurts readability. The formatter converts everything to block style for consistency.

YAML Gotchas That Silently Break Configs

Some YAML problems aren’t about indentation at all — they’re about how YAML interprets bare, unquoted values. These are the bugs that pass every “is it valid YAML?” check and still ship the wrong config.

The Norway Problem

The most infamous YAML gotcha: unquoted no, yes, true, and false are parsed as booleans, not strings. Write a list of country codes and NO (Norway) silently becomes false:

countries:
  - US
  - GB
  - NO   # parsed as the boolean false, not "NO"

Run it through the formatter and the value normalizes to false, making the bug obvious. The fix is to quote it: - "NO". The same trap catches any string that merely looks like a boolean.

Version Numbers and Leading Zeros

Unquoted version: 1.10 is read as the number 1.1 — the trailing zero vanishes. A build number or ZIP code like 08544 can be treated as a number and lose its leading zero. Always quote values that are semantically strings: version: "1.10", zip: "08544".

Duplicate Keys

YAML doesn’t error on duplicate keys in the same mapping — the last one silently wins. If a config has replicas: 2 near the top and replicas: 5 fifty lines down, only 5 survives after parsing. Formatting collapses the duplicates so the winner is visible; review the diff to confirm it’s the value you intended.

“mapping values are not allowed here”

This cryptic parser error almost always means an unquoted value contains a colon — a URL (url: http://example.com), a timestamp (time: 12:00), or a Windows path. Wrap the value in quotes and the error disappears. This formatter auto-quotes ambiguous values for you, so pasting the broken snippet and formatting it is often the fastest way to spot and fix it.

Formatting YAML for DevOps

Kubernetes Manifests

Kubernetes YAML files are where formatting matters most. A Deployment, Service, or ConfigMap with inconsistent indentation is harder to review, easier to misread, and more likely to cause an accidental field relocation during editing. Format your manifests before committing — especially multi-document files separated by ---.

Docker Compose

docker-compose.yml files grow quickly as services multiply. Formatting keeps the services, volumes, networks, and environment sections visually aligned, making it obvious which keys belong to which service.

CI/CD Pipelines

.gitlab-ci.yml, .github/workflows/*.yml, and .circleci/config.yml are edited frequently and often by multiple people. Formatting before committing reduces diff noise in pull requests and ensures the file stays consistent even as the team grows.

Ansible Playbooks

Ansible playbooks and roles are deeply nested YAML that benefits heavily from consistent formatting. A formatter turns a messy playbook into one where tasks, handlers, and vars are immediately scannable.

Block Scalars: Multi-Line Strings in YAML

Long strings — a shell script in a CI job, a certificate block, an embedded config — use block scalars, and formatting them wrong is a common source of broken pipelines. YAML has two styles:

  • Literal (|) preserves every newline exactly as written. Use it for scripts and anything where line breaks matter.
  • Folded (>) joins lines with spaces into a single flowing paragraph, collapsing the newlines. Use it for long prose that should wrap.

Each can take a chomping indicator that controls the trailing newline: - strips it (|-), + keeps every trailing blank line (|+), and the bare form keeps exactly one. The formatter parses these blocks, preserves the literal-vs-folded distinction, and re-indents the body under its parent key so the block stays valid:

script: |
  set -e
  npm ci
  npm test  

If a multi-line block “disappears” or merges into the wrong key after editing, it’s almost always an indentation problem — the block body must be indented further than the key that introduces it. Running it through the formatter re-establishes that relationship.

YAML Formatter vs YAML Validator

These tools solve different problems and work best together:

YAML FormatterYAML Validator
PurposeClean up indentation and styleCheck for syntax errors
InputValid YAML (or close to it)Any text that should be YAML
OutputRe-formatted YAMLError report or “valid”
CommentsStripped (data is re-serialized)Preserved (text is analyzed)
Best forMaking YAML readable and consistentFinding bugs before deploy

Workflow: validate first to catch syntax errors, then format to normalize style. Our YAML Validator handles the first step.

YAML Formatting Best Practices

Pick One Indent Size and Enforce It

Two spaces is the community standard. Set it in your editor, your .editorconfig, and your CI linter. Don’t mix indent sizes across files in the same project.

Sort Keys for Deterministic Output

Alphabetically sorted keys produce smaller, cleaner diffs when configurations change. This is especially valuable for values.yaml in Helm and docker-compose.yml — two files that change frequently and are reviewed by multiple people.

Format Before Committing

Add YAML formatting to your pre-commit hook or CI pipeline. Tools like Prettier (with prettier-plugin-yaml), yamlfmt (Google’s Go-based formatter), or this online tool for quick one-off checks ensure every committed YAML file meets the same standard.

Use Block Style Over Flow Style

Block style (one key-value pair per line, indented) is more readable and produces better diffs than flow style (inline {key: value}). Reserve flow style for very short, simple values like ports: [80, 443].

Frequently Asked Questions

What is a YAML formatter?

A YAML formatter takes YAML data with inconsistent or messy indentation and re-formats it with clean, uniform spacing. It normalizes indent levels, aligns keys, and produces readable YAML that follows common conventions — making config files easier to read, review, and maintain.

How do I format YAML online?

Paste your YAML into the input area and click 'Format' or press Ctrl+Enter. Choose your preferred indentation (2 or 4 spaces) in the settings. The tool re-parses your YAML and outputs a cleanly indented version. Copy the result with one click.

Can I format Kubernetes manifests and Helm values files?

Yes. Kubernetes Deployments, Services, ConfigMaps, Helm values.yaml, and kustomization.yaml are all standard YAML. Paste them in and the formatter normalizes indentation. Note that comments are not preserved during formatting — back them up if they matter.

What indentation should I use for YAML?

Two spaces per level is the most common convention and the default in most tools, linters, and style guides (including the Kubernetes community). Four spaces is also valid but less common. Tabs are forbidden by the YAML specification.

Does this formatter preserve comments?

No. The formatter parses YAML into a data structure and re-serializes it, which strips comments. This is the same behavior as most programmatic YAML formatters. If you need to keep comments, use a text-editor plugin that reformats in-place (like Prettier with a YAML plugin).

What is the difference between a YAML formatter and a YAML validator?

A YAML validator checks whether your YAML is syntactically correct and reports errors. A YAML formatter goes further — it parses valid YAML and re-outputs it with consistent, clean indentation. Use the validator to find errors, then the formatter to clean up the style. Try our YAML Validator for syntax checking.

Is my YAML data safe with this tool?

Yes. All processing happens entirely in your browser using JavaScript. Your YAML is never sent to any server, never logged, and never leaves your machine — safe for CI configs, Kubernetes secrets, and infrastructure files.

Why did my YAML value 'no' or 'yes' turn into false or true?

This is the famous 'Norway problem.' YAML interprets unquoted 'no', 'yes', 'true', and 'false' as booleans, so a country code like NO becomes the boolean false. Quote the value — 'NO' — to keep it a string. The formatter makes this coercion visible so you can catch it before it ships.

What does the Compact button do?

Compact strips all comments and collapses blank lines without re-serializing the document, keeping your original indentation and key order. Use Format to rebuild the file with clean, uniform indentation; use Compact to quickly remove noise before pasting into a ticket, chat, or kubectl command.

How do I fix the 'mapping values are not allowed here' error?

That error means an unquoted value contains a colon — usually a URL, timestamp, or Windows path. Wrap the value in quotes, for example url: 'http://example.com'. This formatter automatically quotes ambiguous values, so pasting the broken YAML and formatting it is often the fastest fix.