YAML Formatter and Beautifier

Re-indent YAML consistently without losing your comments, anchors or document separators. Syntax errors are shown with their line number as you type.

Input
Output

    Nothing leaves your browser. Shortcut: Ctrl/⌘ + Enter runs the main action.

    What is a YAML formatter?

    A YAML formatter rewrites a YAML file with consistent indentation and spacing while keeping the same data. Because indentation is part of YAML's syntax, hand-edited files easily drift: one block indented with 4 spaces, the next with 2, list items sometimes indented and sometimes not. A formatter normalises all of that so the file is easier to review and produces clean diffs. This one is built on a full YAML 1.2 parser that keeps comments, which plain YAML-to-data-to-YAML round trips lose.

    How to format YAML

    1. Paste YAML or open a .yaml / .yml file. It is checked as you type.
    2. Choose 2 or 4 spaces and decide whether to sort keys alphabetically.
    3. Click Format. Copy or download the result, or convert it with To JSON.

    Example

    Input with mixed indentation and a comment:

    services:
        web:   # public entry point
            image: nginx:1.27
            ports:
            - "80:80"
        db:
          image: postgres:16

    Formatted with 2 spaces:

    services:
      web: # public entry point
        image: nginx:1.27
        ports:
          - "80:80"
      db:
        image: postgres:16

    What the formatter changes and what it keeps

    ChangesKeeps
    Indentation of mappings and sequencesComments, including inline comments
    Spacing after colons and dashesAnchors, aliases, tags and merge keys
    Key order, only when Sort keys is tickedQuoting style of strings, block scalars
    Flow collections are kept, with normalised spacingDocument separators (---) in multi-document files

    When the YAML is invalid

    Formatting needs a document that parses. If it does not, the problems list shows the line and column of each error together with a plain explanation: a tab used for indentation, a key without a space after its colon, a line indented to a level that matches no parent, an unclosed bracket or quote, or a duplicate key. The YAML validator page explains each of these in detail. The formatter also warns about values that YAML 1.1 tools read differently, such as an unquoted no or 0755.

    Need the same data in another format? Use YAML to JSON. Comparing two versions? Use the YAML diff.

    YAML formatter questions

    Does the YAML formatter keep comments?

    Yes. The formatter works on the YAML document tree, not on plain data, so comments stay attached to the keys and items they describe. Anchors (&name), aliases (*name), tags and --- document markers are kept too.

    Why can't I choose tabs for YAML?

    The YAML specification forbids tab characters for indentation; only spaces are allowed. The Tab option is therefore disabled for YAML output.

    How are list items indented?

    Items of a sequence are indented under their parent key (key:\n - item), which is the style used by Kubernetes, GitHub Actions and most style guides, and what yamllint accepts by default.

    Can it format files with several documents?

    Yes. A file with multiple documents separated by --- (common for Kubernetes manifests) is formatted document by document and the separators are kept.

    Will formatting change values?

    No. Values are written back in the same style where possible: quoted strings stay quoted, block scalars (| and >) keep their content, numbers keep their notation. The formatter only changes indentation and spacing.