YAML writes long text with block scalars. A pipe (|) keeps every line break exactly as typed; a greater-than sign (>) folds single line breaks into spaces. A chomping indicator then decides the ending: - removes the final newline, nothing keeps one, and + keeps every trailing blank line too.
| Header | Line breaks inside | End of the string |
|---|---|---|
| | | Kept | One newline |
| |- | Kept | No newline |
| |+ | Kept | Newline plus every trailing blank line |
| > | Single breaks become spaces | One newline |
| >- | Single breaks become spaces | No newline |
| >+ | Single breaks become spaces | Newline plus every trailing blank line |
Updated
The header line after the key is two characters at most, yet it decides what your program receives. Choose a style and a chomping indicator in the preview, type some text, and the exact string appears below in JSON notation so every newline is visible as \n.
Type the text, choose a style and a chomping indicator, and see the YAML you would write next to the exact string a parser returns.
Literal style keeps each command on its own line, which is what the shell needs.
steps:
- name: Build and test
run: |
npm ci
npm run build
npm testFolded and stripped: the value is one line of text with no newline at the end.
description: >-
Fresh sourdough, pastries and coffee,
baked every morning on the harbour front
since 2009.
# value: "Fresh sourdough, pastries and coffee, baked every morning on the harbour front since 2009."With + the blank line after the text stays in the value, so the parsed string ends in two newlines.
footer: |+
Sent from the shop
next: value
# footer = "Sent from the shop\n\n"
Folding only joins two neighbouring lines that both start at the block's own indentation. One break between them becomes a space. If you leave one blank line, the value gets a single newline instead, which is how you write paragraphs.
A line that begins with extra spaces is left alone, and so are the breaks on either side of it. That is the rule the preview applies, so try indenting one line to watch it happen.
If the first content line has to start with spaces, YAML cannot guess the indentation. Add a digit to the header, as in |2, to say how many spaces the block is indented relative to its parent.
The digit and the chomping sign can be combined in either order, for example |2- or |-2.
The pipe starts a literal block: every line break you type stays in the value. The greater-than sign starts a folded block: a single break between two ordinary lines turns into a space, while blank lines become newlines.
It is the strip chomping indicator. The final line break and any blank lines after the text are dropped, so the value ends at the last visible character.
It is the keep indicator. The final line break and every trailing blank line become part of the value. Without any indicator, YAML clips: it keeps one final newline and drops the blank lines.
Lines that start with extra indentation are more-indented lines. Folding never joins them, so the breaks around them are preserved. This lets you keep a code sample or a list inside folded prose.
Yes. A double-quoted string may contain \n escapes, and quoted or plain scalars may continue over several lines, where each single break folds into a space. Block scalars are easier to read once text gets long.
Related: YAML vs JSON, YAML comments, YAML to JSON converter, YAML front matter.
Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.
We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.