YAML Formatter
Re-indent YAML without losing comments or rewriting your numbers — entirely on this device.
Formatting changes layout only — keys, values and comments are preserved; numbers and quoted strings are re-emitted byte-exact. YAML forbids tabs in indentation.
Press ? for shortcuts
Do it offline:$ yq -P '.' file.yaml
How to use it
- Paste YAML or drop a .yml file — up to 20 MB, with an explicit button naming the size once the input gets large.
- Set the indent unit, whether sequences indent under their key, folding at 80 columns, flow-to-block expansion and quote style. There is no tab choice, because YAML forbids tabs in indentation.
- Copy or download the result, or share the tool state as a link; a document that will not parse shows the parser's own positioned message and a hand-off to the validator.
Paste YAML and get it back re-indented: comments stay attached to what they describe, numbers keep the digits you typed, and multi-document streams stay separate. The rewrite runs on this device, so nothing you paste is transmitted.
Examples
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
spec:
replicas: 3
template:
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
spec:
replicas: 3
template:
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
A four-space manifest halved to two. Nesting depth is unchanged — only the width of each step — and the chip reads “indentation rewritten to 2 spaces”.
# service config
server: # bind here
host: 0.0.0.0
port: 8080
# timeouts in seconds
timeouts:
read: 30
write: 30
# service config
server:
# bind here
host: 0.0.0.0
port: 8080
# timeouts in seconds
timeouts:
read: 30
write: 30
Both comments survive with their text intact. The trailing one on the server line moves above the block it introduces, and the double blank line becomes one — each reported as its own chip.
spec: {replicas: 2, image: "nginx:1.27"}
ports: [80, 443]
spec:
replicas: 2
image: "nginx:1.27"
ports:
- 80
- 443
Expand to block turns JSON-ish inline collections into indented YAML, quote marks and all. Leave the option on Preserve and the braces stay; the chip counts the two collections that changed shape.
mode: 0777
mask: 0x1F
id: 12345678901234567890
ratio: 1.20
scale: 1e3
zero: -0
mode: 0777
mask: 0x1F
id: 12345678901234567890
ratio: 1.20
scale: 1e3
zero: -0
The edge case worth checking in any formatter: file modes, hex masks, twenty-digit identifiers, trailing zeros and exponents come back character for character, because scalars are re-emitted from their source text rather than from a parsed number.
---
name: first
items: [a, b]
---
name: second
...
---
name: first
items: [ a, b ]
---
name: second
...
Each document in a stream is formatted on its own, and the --- and ... markers stay where you put them. A flow collection kept in flow style gains one space inside its brackets — the only byte that moved here.
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
Indentation is spaces, and only spaces
The spec allows exactly one indentation character, and a tab is not it — which is why this page offers 2 or 4 spaces and no tab option. A tab inside a scalar value is ordinary text and survives.
A comment on a key line moves above the block
YAML attaches a comment to the node that follows it, so a note trailing a key that introduces an indented block cannot stay on the key line — it moves directly above the first child, text unedited.
Blank-line runs collapse to a single separator
Three empty lines between two sections come back as one. Blank lines carry no meaning outside literal blocks, so they are normalized rather than counted; the chip names the before and after totals so nothing is silent.
A byte-order mark is dropped, CRLF becomes LF
Files exported from Windows editors often start with an invisible mark and end every line with two characters. The output is plain UTF-8 with single newlines, and both changes are reported rather than assumed to be welcome.
A file with no document is returned untouched
Empty input, pure whitespace, or a file holding only comments contains zero documents. Rather than emit nothing, the tool hands back your bytes exactly as pasted and says so — losing a header comment to a formatter would be indefensible.
Common errors
Tabs are not allowed as indentation at line 2, column 1: root: child: 1 ^- The single most common YAML failure, and invisible in most editors. Replace the tab with spaces; a tab inside a value is fine, it is only indentation that is forbidden.
Flow map in block collection must be sufficiently indented and end with a } at line 2, column 1: map: {a: 1 ^- An inline collection was opened and never closed, so the parser ran to the end of the file looking for the bracket. The position points at where it gave up, not at the opening brace.
Nested mappings are not allowed in compact mappings at line 1, column 4: a: 1 ^- A line is indented deeper than its parent allows, so the reader sees a mapping starting inside a value that is already complete. Align the key with its siblings and the document parses.
This tool formats up to 20MB; beyond that, try the CLI: yq -P '.' file.yaml- Formatting half a stream would produce a file that no longer says what the original said, so the whole input is refused instead. The CLI handles arbitrarily large files.
FAQ
Can re-indenting change what my YAML means?
It should not, and the build proves it: every example here that two other YAML readers can represent is re-parsed by both and compared against the original before the page ships, and the numeric example is checked character by character instead, because older readers rewrite those scalars themselves. What moves is layout — indent width, line breaks, bracket style.
Why is there no option to indent with tabs?
Because the result would not be YAML. The specification permits space characters alone for indentation, and every conforming reader rejects a tab there — offering the choice would just be a way to generate broken files. Tabs inside quoted or literal values are unaffected.
Will my numbers survive exactly as written?
Yes. A leading-zero file mode, a hex mask, an exponent and a twenty-digit identifier are re-emitted from the characters you pasted, not from a parsed value, so nothing is re-based, rounded or padded. Quoted strings are handled the same way while the quote style stays on Preserve.
Keyboard shortcuts
- ⌘/Ctrl + Enter
- Run the formatter — the only way to start once the input is large.
- ⌘/Ctrl + S
- Save the formatted stream as a .yaml file.
- ⌘/Ctrl + C
- With nothing selected, put the whole output on the clipboard.
- ⌘/Ctrl + Shift + C
- Take the full output even when part of it is selected.
- t
- Step the theme forward, unless a text field has focus.
- ? or ⌘/Ctrl + /
- Show every binding this page listens for.
- Esc
- Back out of the frontmost dialog, leaving both panes as they are.