Home / YAML tools / YAML formatter

YAML Formatter

Paste YAML and get clean, consistently indented code. Comments and blank lines are kept, and the syntax is checked as you format.

Options

Result

What the YAML formatter does

A YAML formatter rewrites your file with steady indentation and spacing, without changing what it means. This one reads the YAML with a full parser, so it understands the structure, and it writes the file out again in a clean layout.

# Before
server: {host: localhost,   port: 8080}
paths:
    - /api
    -   /health

# After
server: { host: localhost, port: 8080 }
paths:
  - /api
  - /health

Your comments are kept

Many converters throw away comments, because they turn the YAML into data and back. This formatter keeps the comments, both the ones on their own line and the ones at the end of a line, and it keeps the blank lines that separate sections. Turn on Remove comments if you want a clean copy without them.

Values are never changed

The formatter changes layout only. A number such as 0755 or 1.10, a value written as yes, a long number and a quoted string all come out exactly as you wrote them. The output is checked against the input on many real files, and the data was the same every time.

Options

  • Indent: 2 or 4 spaces. YAML does not allow tabs for indentation.
  • Wrap long lines at: folds long text at the width that you choose, or leaves lines as they are.
  • Indent list items under their key: writes lists as key: then an indented - item, or with the dash lined up under the key when it is off.
  • Expand flow style: turns the short forms {a: 1} and [1, 2] into the block form on separate lines.
  • Sort keys: puts the keys of every mapping in alphabetical order.
  • Quotes: keeps your quotes, or changes quoted text to single or double quotes where that is allowed.

Syntax errors are reported

If the YAML is not valid, nothing is changed. Instead, you see each error with its line and column and a small excerpt of the code, so that you can fix it. See the YAML validator for more detail on the checks.

More than one document

A file can hold several YAML documents separated by three dashes. All of them are formatted, and the separators are kept. This is common in Kubernetes files.

Your YAML is processed in your browser and is not uploaded. For a looser layout use the YAML beautifier, to convert use YAML to JSON or JSON to YAML, and for the rules of the language read the YAML syntax guide.

Frequently asked questions

How do I format YAML online?

Paste your YAML into the box and press Format YAML. Choose the indent and any options, then copy the result.

Does the formatter keep my comments?

Yes. Comments and blank lines are kept. There is an option to remove the comments if you want to.

Will formatting change my data?

No. Only the layout changes. Numbers, strings and quotes keep their values.

Can I use tabs for indentation in YAML?

No. The YAML specification forbids tabs for indentation, so the formatter always uses spaces.