HomeFormattersDataYAML Formatter

YAML Formatter

Data

Format and validate YAML instantly in your browser. Catch syntax errors, normalise indentation, and produce clean output — nothing is ever uploaded anywhere.

What is a YAML?

The YAML Formatter parses raw or inconsistently indented YAML and produces a clean, consistently indented document with normalised structure. It uses a full, specification-compliant YAML parser — not a regex-based approach — which means it validates the input as it formats and returns a meaningful error message if the YAML is syntactically invalid.

YAML (YAML Ain't Markup Language) is the dominant format for developer configuration files. Docker Compose, Kubernetes, GitHub Actions, Ansible, Rails, and dozens of other tools use YAML for their configuration. It is human-friendly by design — indentation conveys structure, comments are supported, and strings do not need quotes in most cases. But this flexibility also makes YAML easy to break: a single misaligned indent or an extra tab character can produce a cryptic parse error.

Formatting YAML by hand is tedious and error-prone. When you paste a YAML snippet from documentation, a colleague's message, or an AI tool, the indentation may be inconsistent — mixing 2-space and 4-space indentation, using different styles for list items, or producing trailing whitespace that is invisible but breaks strict parsers. The YAML Formatter normalises all of this into a single consistent style in one step.

The formatter supports your choice of 2-space or 4-space indentation per level. Two spaces is the default for Kubernetes and GitHub Actions; four spaces suits teams that prefer more visual depth. All processing runs locally in your browser — the YAML you paste is never sent to a server. This is important when the YAML contains secrets, API keys, or deployment credentials, as is common in CI/CD and infrastructure configuration files.

For related structured data formats, use the JSON Formatter for JSON payloads or the XML Formatter for XML documents.

How to use this YAML calculator

  1. Paste your YAML into the Raw YAML input box — this can be a configuration snippet, a full manifest, or a YAML document of any length.
  2. Choose an Indent Size from the dropdown: 2 spaces (default, matches Kubernetes and GitHub Actions convention) or 4 spaces.
  3. The Formatted YAML output updates instantly. If the input is invalid YAML, the output shows the parse error message.
  4. Review the output to confirm the structure and values look correct.
  5. Click Copy to copy the formatted YAML to your clipboard.

Formula & Methodology

The YAML Formatter uses a two-phase approach built on the yaml library (YAML 1.2 compliant):

Phase 1 — Parse: yaml.parse(input) converts the YAML string into a JavaScript value tree (nested objects, arrays, and primitives). If the input contains a syntax error, parse throws an error with a message that includes the line and column of the problem. This error is caught and returned as the output string.

Phase 2 — Stringify: yaml.stringify(parsed, { indent }) serialises the JavaScript value tree back to a YAML string using the chosen indent size. The output is always canonical YAML 1.2: keys are not sorted but are preserved in the order they appeared in the input; strings that require quoting (empty strings, values that would be misread as booleans or nulls) are automatically quoted; trailing whitespace and blank lines at the end are trimmed.

Before (inconsistent indentation):
yaml server:     host: localhost     port: 8080 database:   name: myapp   user: admin 

After (2-space indent, normalised):
yaml server:   host: localhost   port: 8080 database:   name: myapp   user: admin 
Frequently Asked Questions
What is YAML?
YAML (YAML Ain't Markup Language) is a human-readable data serialisation format used for configuration files, data exchange, and settings. It uses indentation to represent structure — similar to Python — and supports strings, numbers, booleans, lists, and nested mappings without the verbosity of XML or the quote-heaviness of JSON. YAML is the native format for Docker Compose files, GitHub Actions workflows, Kubernetes manifests, Ansible playbooks, and many web frameworks' configuration files.
What is the difference between YAML and JSON?
YAML and JSON represent the same kinds of data (strings, numbers, booleans, arrays, objects), but YAML is designed for human authoring while JSON is designed for machine exchange. YAML uses indentation instead of braces and brackets, allows unquoted strings, and supports comments (which JSON does not). JSON is a strict subset of YAML 1.2, meaning any valid JSON is also valid YAML. YAML is generally preferred for configuration files that humans edit; JSON for API responses and data storage.
What does the YAML Formatter do?
The YAML Formatter parses your YAML input, checks it for syntax errors, and serialises it back with consistent indentation and normalised structure. The result is a clean, canonical YAML document with predictable key ordering and uniform spacing. If the input contains a syntax error, the formatter reports the error message rather than attempting to format broken YAML.
What indent size should I use for YAML?
Two spaces is the most widely used YAML indentation — it is the default in Kubernetes, GitHub Actions, Docker Compose, and most YAML generators. Four spaces is used in some organisations that prefer more visual depth. YAML does not allow tab characters for indentation; only spaces are valid. Both 2-space and 4-space YAML is valid as long as it is consistent within the document.
Can the formatter fix YAML syntax errors?
No. The formatter uses a full YAML parser (not a regex-based approach) to validate the input. If the input is invalid YAML — misaligned indentation, an unclosed string, or an invalid character — the parser returns an error and the formatter displays that error message instead of attempting to format broken input. You must fix the syntax error before the formatter can produce clean output.
Does YAML support comments?
Yes — YAML supports line comments starting with `#`. However, comments are attached to the document structure rather than to specific keys, and many YAML parsers (including the one used in this formatter) discard comments during parsing and serialisation. If your YAML has important comments, they will not appear in the formatted output. This is a fundamental limitation of YAML's comment handling across most libraries.
How do I format YAML?
Paste your YAML into the Raw YAML input box, select an indent size (2 or 4 spaces), and the Formatted YAML output updates instantly. If your input has a syntax error, the output shows the error message. Click the Copy button to copy the formatted YAML to your clipboard.
Is my YAML uploaded anywhere?
No. All parsing and formatting happens entirely in your browser using the `yaml` library compiled to JavaScript. The YAML you paste — which may include API keys, database credentials, deployment configuration, or internal environment variables — is never sent to any server, stored, or logged.
Does this work offline?
Yes — once the page has loaded, the YAML Formatter runs without a network connection. The YAML parser and serialiser are bundled JavaScript that executes entirely in your browser tab.
What YAML version does this support?
The formatter uses the `yaml` library by Eemeli Aro, which implements YAML 1.2. YAML 1.2 is the current specification and resolves several ambiguities from YAML 1.1 — notably, it no longer treats `yes`, `no`, `on`, and `off` as booleans (only `true` and `false` are). Most modern YAML tools target YAML 1.2.
Can I use this for Kubernetes or GitHub Actions YAML?
Yes. Both Kubernetes manifests and GitHub Actions workflow files use standard YAML and can be formatted with this tool. Kubernetes YAML with `apiVersion`, `kind`, `metadata`, and `spec` blocks formats cleanly. GitHub Actions `on`, `jobs`, and `steps` keys are preserved. Note that comments in your workflow file will be stripped, so if your workflow file has inline comments, keep a copy of the original before formatting.