YAML Formatter
Format, validate, and pretty print your YAML files with customizable indentation levels.
Make indentation predictable before a config review
YAML is comfortable to read precisely because indentation carries structure. That advantage becomes a liability when a copied deployment file mixes two-space and four-space levels, a tab slips into leading whitespace, or list markers drift away from neighboring mappings. This online YAML formatter gives you a quick, visual normalization pass: paste a document, choose two or four spaces, and inspect the rewritten result beside the source.
The formatter works line by line. It finds the smallest indentation used by a nonblank, noncomment line and treats that width as one original nesting level. It then translates every level to the selected output width. This is useful when a repository has a clear indentation convention and an incoming snippet uses another. Output refreshes as the input or indent setting changes, so comparing both styles takes one selection rather than a separate formatting run.
This is a focused beautifier, not a complete YAML 1.2 processor. It catches several layout problems and standardizes common mapping and sequence lines, but it does not construct a YAML representation graph or resolve tags, anchors, aliases, directives, schemas, and scalar types. That distinction matters: readable output is not proof that an application will accept the document.
A before-and-after example
Suppose a service file arrived with four-space levels and inconsistent spacing around sequence markers:
service:
image: api:latest
environment:
- name: LOG_LEVEL
value: info
command: |
node server.js
--port 8080
With 2 Spaces selected, this free YAML formatter produces:
service:
image: api: latest
environment:
- name: LOG_LEVEL
value: info
command: |
node server.js
--port 8080
Notice an important limitation in that output: the formatter treats the first colon on a mapping-like line as the key separator. An unquoted value such as api:latest is rewritten as api: latest. If a colon is significant inside a scalar, quote the scalar before relying on this formatter. The side-by-side view makes changes like this easy to catch before copying or downloading.
What the formatter actually changes
Indentation width
The Indent menu offers exactly two choices: 2 Spaces and 4 Spaces. Tabs are not an output option because YAML indentation uses spaces. The detected source width is converted by nesting level; the tool does not merely prepend a fixed number of spaces to every line.
Mapping spacing
For a line containing a colon, text before the first colon is trimmed and emitted as the key, followed by : and one space when a value exists. A missing key, such as : value, produces a line-specific syntax error. This normalization handles ordinary block mappings well, but the first-colon rule is deliberately simpler than YAML’s full plain-scalar grammar.
Sequence markers
Lines beginning with - are normalized to a dash followed by one space when an item follows. If the sequence item itself looks like a mapping, the first colon in the remainder receives standard key-value spacing. A bare sequence marker remains -.
Comments and blank lines
Blank lines are retained. A # is treated as an inline comment when the text before it contains balanced counts of single and double quote characters. The comment is preserved and separated from preceding content by one space. This quote-count heuristic handles straightforward comments, but it is not equivalent to parsing escaped quotes or every YAML scalar style.
Literal and folded blocks
Lines ending in | or > start a multiline region. More-indented content underneath is carried over with its relative indentation adjusted from the new base. This protects common literal and folded block scalar layouts, including shell commands and message bodies. Chomping indicators such as |- or >+ do not match the tool’s simple end-character check, so review those blocks manually.
A practical repository workflow
- Open the file in your editor and identify the repository’s expected width, usually from adjacent YAML files.
- Paste the candidate document into Input YAML. The formatted pane updates immediately.
- Resolve any tab error first. The message names the line where leading indentation contains a tab character.
- Resolve inconsistent indentation warnings. The warning reports the number of leading spaces and the detected source multiple.
- Choose two or four spaces and compare structural levels in both panes.
- Scan quoted values, URLs, image tags, timestamps, and other scalars containing
:or#because line-based normalization can interpret those characters structurally. - Use Copy for an editor paste or Download to save
formatted.yamlwith thetext/yamlmedia type. - Run the result through the parser, schema check, or application that owns the configuration before committing it.
Copy and Download remain disabled when there is an error or no formatted output. Clear empties both panes and resets the error state. Processing happens in the page as you type; there is no upload step in this component.
Understanding the warnings
The formatter reports three specific classes of issue. A leading tab yields “YAML does not allow tab characters for indentation,” together with the line number. Indentation that is not a multiple of the detected base yields a validation warning. A colon with no key yields “Key cannot be empty before ‘:’.” These messages are useful for repairing layout, but they should not be read as exhaustive YAML validation.
For example, this text may look suspicious to a YAML parser for reasons the formatter does not diagnose:
defaults: &defaults
retries: 3
worker:
<<: *defaults
enabled: maybe
Anchors and aliases are left as text. Whether maybe is a string or a schema-specific boolean depends on the consuming parser. The formatter neither resolves the merge key nor tells you which schema applies.
Where an online YAML pretty printer helps most
Small configuration reviews are the ideal use case. Normalize a Kubernetes manifest excerpt before discussing it in chat; make a CI workflow easier to compare; convert a four-space example from vendor documentation to a two-space repository convention; or clean a short application settings file before opening a pull request. A browser-based, free online YAML formatter is also convenient on a machine where no project formatter is installed.
For generated files, very large documents, or formats with extensive anchors and custom tags, prefer the project’s established parser and formatter. Automated tooling can preserve semantic context, apply the exact YAML version expected by the application, and run reproducibly in continuous integration. This page is best used as an inspection aid rather than a replacement for that pipeline.
Formatting checklist
- Confirm every indentation level represents the intended parent-child relationship.
- Check that sequence items belong to the expected key.
- Inspect any scalar containing a colon or hash character.
- Verify block scalar indentation and chomping behavior.
- Keep tabs out of leading whitespace.
- Parse the final text with the target runtime.
- Validate domain rules separately, such as a Kubernetes or OpenAPI schema.
Questions developers ask
Does this tool validate YAML 1.2 syntax?
No. It performs layout-oriented checks and rewrites common block mapping and sequence lines. It does not implement the complete YAML 1.2 grammar, compose nodes, or validate tags and schemas. Use a real YAML parser for an authoritative syntax result.
Why does it report inconsistent indentation on a visually aligned line?
The formatter infers one source indent width from the smallest positive indentation among content lines. Every later indentation must be a multiple of that width. Alignment spaces used for presentation can therefore trigger a warning even when they were intentional.
Can I format with tabs?
No. The available output widths are two spaces and four spaces. A tab in leading whitespace is reported with its line number.
Are comments removed?
Ordinary full-line comments and straightforward inline comments are retained. Detection of inline comments uses a quote-count heuristic, so complicated escaped quoting deserves manual inspection.
Will literal block content be reflowed?
No prose reflow occurs. For blocks introduced by a line ending in | or >, the tool preserves content lines and adjusts their indentation relative to the reformatted parent.
What file does Download create?
It creates formatted.yaml. The downloaded text is exactly what appears in the output pane.