YAML Multiline Strings: | and >, Explained with a Live Preview
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.
Block scalar preview
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.
Block scalars in real files
Shell commands in a CI step
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 testA long description folded into one paragraph
Folded 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."Keeping trailing blank lines
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"
How folding really works
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.
Indentation indicators
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.
How it works
- Type or paste the text you want to store. Each line in the box becomes one content line of the block.
- Pick literal (|) or folded (>), then strip (-), clip (default) or keep (+).
- Set how many blank lines follow the block to see what keep does with them.
- Copy the YAML on the left. The right side is the string a YAML 1.2 parser hands to your code.
Tips
- Use |- for values compared as exact strings, such as tokens or certificates pasted into config, so no stray newline sneaks in.
- Use > for long prose that should read as one paragraph in the program but wrap nicely in the file.
- Shell steps in CI files usually want |, because each command must stay on its own line.
- Indent the content further than the key. The first non-empty line sets the indentation for the whole block.
Frequently asked questions
What is the difference between | and > in YAML?
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.
What does the minus sign in |- mean?
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.
What does + do after | or >?
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.
Why are some lines not folded in my > block?
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.
Can I write a multi-line string without block scalars?
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.
More in Guides
- YAML vs JSON: Which One, and Why
- Your Connection Is Not Private: Causes and Fixes
- 400 Bad Request: What Was Wrong With the Request
- 401 vs 403: Pick the Right Status for a Refused Request
- 403 Forbidden: Why the Server Refuses and How to Fix It
- 404 Not Found: Why Pages Go Missing and How to Fix It
- 404 Page Examples: 20 Designs With Copy-Paste Code
- 409 Conflict: When a Request Clashes With Current State
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App