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.

The six block scalar headers and what they produce
HeaderLine breaks insideEnd of the string
|KeptOne newline
|-KeptNo newline
|+KeptNewline plus every trailing blank line
>Single breaks become spacesOne newline
>-Single breaks become spacesNo newline
>+Single breaks become spacesNewline 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 test

A 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

  1. Type or paste the text you want to store. Each line in the box becomes one content line of the block.
  2. Pick literal (|) or folded (>), then strip (-), clip (default) or keep (+).
  3. Set how many blank lines follow the block to see what keep does with them.
  4. Copy the YAML on the left. The right side is the string a YAML 1.2 parser hands to your code.

Tips

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

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.

Product

Who It's For

Features

Resources

Company

View Sitemap