YAML Formatter Online

Beautify, validate, and reformat YAML files instantly in your browser.

Indent:
INPUT0 chars
OUTPUT

When a YAML formatter is the right tool

YAML often arrives messy: a hand-edited values file, a dump with inconsistent indent, or a snippet copied from a ticket. A formatter is for that moment. You paste the text and get a consistently indented document back — or a parser error if the input is not valid YAML. The output updates as you type. You can choose 2- or 4-space indent and copy the result when it looks right.

This page works on a single document. It parses with js-yaml and writes the value back out, so it will tidy indentation, but it will also drop comments and may rewrite some scalars. If you want to compare two versions without re-serializing them, use YAML Diff. If you only have a Compose file, the Docker Compose Formatter is a more specific starting point.

Use cases

Tidying a values file or a manifest before you read it

Inconsistent indent makes Kubernetes and Helm files hard to scan. Pasting the document here produces a stable 2- or 4-space dump you can actually read, and it confirms that the text parses before you start arguing about a missing key. Load Sample pastes a small app config if you want to try that first.

Catching a syntax error

A missing space after a colon, a tab mixed into indent, or a second document in the same paste will fail with the parser's message. That is more useful than discovering the same mistake later in CI. Fix the text and the output appears again automatically.

Producing a consistent dump to compare later

Two files that differ only in wrapping can be formatted, then pasted into YAML Diff. Be aware that this is a serialize-and-dump step, not a whitespace-only tidy: comments will be gone, and dates or numbers may look different, so you should only do this when you accept that rewrite.

How formatting works

As you type, the input is parsed with yaml.load. If the field is empty, the output stays empty. If parsing fails, the error is shown. If it succeeds, the value is written back with yaml.dump, using your chosen indent (2 or 4 spaces), no line wrapping, and noRefs so anchors and aliases are expanded rather than re-emitted as & / * references. The character count is the length of the input, not of the output. You can copy the output when it is present.

This is a data round trip, not an in-place pretty-printer. Comments are discarded. A compact list may be rewritten with a slightly different block style. Keys may be quoted when the dumper thinks it is safer.

Example — the same mapping, rewritten with consistent indent
name: my-app
dependencies:
  - name: redis
    port: 6379

name: my-app
dependencies:
- name: redis
  port: 6379

The data is the same. The formatter produces a consistent block style and indent. Use the 2- or 4-space control to match the style of the project you are about to paste back into.

Example — comments are dropped on a round trip
# production host
host: api.example.com  # do not change

After a load-and-dump, only host: api.example.com remains. The comments are gone. If those comments matter, do not run the file through this page just to tidy spaces.

Example — a date may be rewritten as a timestamp
release: 2020-01-01

release: 2020-01-01T00:00:00.000Z

A bare date such as 2020-01-01 can be parsed as a timestamp and dumped with a time and a Z suffix. If you compare the original and the formatted copy in YAML Diff, that line will look like a change even though it is the same instant.

What this tool does not do

It does not validate a Kubernetes or Compose schema, preserve comments, format several documents in one stream, or offer a minify mode. It does not sort keys, and it does not send your file to a server. Very large pastes can make the tab feel slow. To turn the same data into JSON, use the JSON to YAML converter, which also converts in the other direction.

How to use YAML Formatter

  1. Paste your YAML into the input pane. The output updates as you type.
  2. Choose 2- or 4-space indent to match the style you need.
  3. If an error appears, fix the syntax — including splitting a multi-document file — and the output will return. Copy the result when it looks right.
  4. Use Load Sample to try a short example, or Clear to start over.

Frequently asked questions

Does the formatter validate my YAML?

It checks that the text can be parsed as a single YAML document. A successful format means js-yaml accepted the input, not that the file matches a Kubernetes, Compose, or JSON Schema. If parsing fails, the error from the parser is shown and there is no output.

Why did my comments disappear?

Comments are not part of the YAML data model this page uses. The input is loaded into a JavaScript value and then dumped again, so # comments are dropped. If you need to keep comments, format in an editor that rewrites whitespace without re-serializing, or compare the original files with YAML Diff instead of formatting them first.

Can I format a multi-document file that uses --- separators?

No. The parser expects a single document. A stream with more than one document (separated by ---) produces an error: expected a single document in the stream, but found more. Split the file and format each document, or compare the raw text with YAML Diff.

Will dates, numbers, and booleans look the same after formatting?

Not always. A value such as 2020-01-01 may be parsed as a timestamp and written back as 2020-01-01T00:00:00.000Z. A number such as 1.0 may be dumped as 1. Some keys are quoted on output. These are serialization choices, not necessarily a change in meaning, but they can surprise you if you expected a byte-for-byte tidy-up.

What do the indent options do?

You can choose 2 or 4 spaces. The output is rewritten with that indent. Line wrapping is turned off, so long lines stay on one line. Anchors and aliases are expanded and the dump does not emit *ref or &anchor markers.

Is my YAML sent to a server?

No. Parsing and rewriting run in your browser as you type. Closing the tab discards what you pasted. Do not paste documents that contain secrets, tokens, or private hostnames if you would not be comfortable with them sitting in memory on this device.

Is there a file size limit?

There is no server-imposed limit, because nothing is uploaded. A few thousand lines is comfortable. A very large dump can make the tab feel slow; in that case, format a smaller excerpt or use a local tool.

Related tools and guides

References

  • YAML 1.2.2 defines documents, collections, and comments. This page formats by loading and dumping through js-yaml, so comments are not preserved and some scalars may be rewritten.
  • Official tools such as kubectl diff or a schema-aware linter are a better fit when you need to know whether a manifest is valid for a cluster, not only whether it parses as YAML.
  • If you need a text comparison that does not re-serialize the file, use YAML Diff on the original documents rather than formatting them first.