Developer Tools
Format and Indent YAML
YAML Formatter for working with YAML config snippets and structured data.
Direct Answer
Use the YAML Formatter when a YAML file has inconsistent indentation, mixed spacing, or is hard to read after being hand-edited or generated. It normalizes indentation and spacing between keys and values while keeping the same keys, values, and document structure.
Why YAML Indentation Is Strict
YAML uses indentation, not brackets or braces, to define nested structure, so the exact number of leading spaces on a line determines which parent it belongs to.
- Indentation must use spaces only; YAML has no defined behavior for tabs and most parsers reject them outright.
- Two spaces per nesting level is the most common convention, though any consistent number works.
- Sibling keys and list items must line up at exactly the same indentation column.
- Mixing indentation widths between sibling blocks is a common source of mapping errors.
Formatting Kubernetes, CI, and Compose Files
These files lean on several YAML features beyond simple key-value pairs, and a formatter needs to handle all of them without breaking their meaning.
- Anchors and aliases let one block be reused elsewhere in the same file without copy-pasting it.
- Multi-document files use a triple-dash separator to hold several independent YAML documents in one file.
- Block scalar indicators control whether line breaks in a multi-line string are preserved or folded into spaces.
- Flow style with braces and brackets can mix with block style in the same file for compact inline values.
How to Use YAML Formatter
- Paste or type your content into the input box.
- The transformed result appears instantly in the result panel below.
- Click Copy result to copy the output to your clipboard.
- Download .txt saves the transformed text as a file.
- Reset clears everything and lets you start over.
Reference
| Feature | Details |
|---|---|
| Purpose | Transform pasted text into a cleaner or different format. |
| Input | Text, lines, lists, or copied content. |
| Result | Transformed text ready to copy or download. |
| Best for | Cleanup, formatting, list preparation, and copy-paste workflows. |
| Category | Developer Tools |
| Works on | Desktop, tablet, and mobile browsers |
Useful Related Tools
Frequently Asked Questions
Why does YAML reject my file with a tab character error?
YAML forbids tabs for indentation entirely; the specification only allows spaces to define nesting depth, so a raw tab character in front of a key or list item causes a parse error rather than being silently converted. Replace leading tabs with spaces, and configure your editor to insert spaces when you press tab in YAML files.
Why did no or yes turn into true or false in my config?
This is known as the Norway problem: YAML 1.1 treats certain unquoted words, including no, yes, on, off, y, and n in various cases, as booleans rather than strings. To keep them as literal text, wrap the value in quotes, like quoted no or quoted yes, so the parser treats it as a string instead of a boolean.
Why did a version number like 1.10 turn into 1.1?
An unquoted value that looks numeric is parsed as a number, not a string, so a trailing zero after a decimal point can be dropped the same way it would be for any float. Quote version strings and similar identifiers that happen to look like numbers so they are preserved exactly as written.
What is the difference between block style and flow style?
Block style uses indentation, dashes, and newlines to represent structure across multiple lines, which is the more common and readable style for config files. Flow style uses braces and brackets in a compact, JSON-like syntax on a single line; both are valid YAML and can be mixed within the same document.
What are anchors and aliases for?
An anchor marks a block of YAML so it can be referenced again elsewhere without repeating it, and an alias inserts that referenced block at another point in the document. This is commonly used in Docker Compose and CI files to define a shared set of defaults once and reuse them across multiple services or jobs, often combined with a merge key to merge the anchored mapping into another one.
Can one YAML file have multiple documents?
Yes, a triple-dash line separates independent documents within a single file, and an optional triple-dot line can mark the end of a document. A formatter should preserve these separators and format each document's content independently rather than treating the whole file as one structure.
Why does formatting move or lose my comments?
Comments starting with a hash are not part of YAML's actual data model, so a formatter that fully parses and re-serializes the document may not always keep a comment attached to the exact line it originally sat next to. A good formatter tries to preserve comment placement, but if precise comment position matters, check the specific tool's behavior before relying on it.
Should I use tabs or spaces for indentation?
Spaces only. Tab indentation is invalid per the YAML specification and will cause a parse error in most tools, even though a tab character might look fine visually in some editors.