Skip to Content

What Is YAML and Can You Write Multiline Strings?

YAML is short for “yet another markup language” or “YAML ain’t markup language,” the latter recursive acronym being used to emphasize that YAML is for data and not documents. YAML is a data serialization language used to write configuration files for deployment of infrastructure. For example, if you want to deploy a Docker application to Kubernetes, you would use a YAML file to configure the instance. YAML is human-readable, so it’s easy to create a file and read instructions from it during deployments.

If you’re new to YAML, it won’t be long before you realize you need a way to break up your strings into multiple lines, one of the most frequently asked YAML questions on the web. In this article, we’ll cover the two main approaches to YAML multiline strings, as well as some other frequently asked questions.

YAML and Whitespace: What to Know

YAML files use whitespaces and carriage returns, but the content is serialized when ingested into a specific resource. Developers creating a YAML file can format text using indents and spacing to make it easier to read. YAML treats whitespaces similarly to other languages, so you can have as many as needed to format a file.

How to Break Lines for YAML Multiline Strings

When ingesting YAML files, you might occasionally want to keep the line breaks in a multiline string. Take the following pseudocode as an example:





After every line item (e.g., item1, item2, and item3), you have a carriage return. If you leave the YAML syntax as is, the string becomes the following:

item1 item2 item3

This string format creates one long string without any carriage return formatting, so you might want to preserve the line breaks. Line breaks can be preserved with the literal operator. The literal operator is the pipe (“|”) character. To preserve line breaks, your YAML syntax should be changed to the following:

    key: |




Notice the pipe character after the “key” directive. When the application ingests the YAML file, it will convert to the following string:


The “\n” character represents a new line. Printing this string to an application will display each item with an appended carriage return to preserve the formatting in the YAML instructions.

YAML Multiline Blocks vs. Long Strings

For long strings, you need to use multiline blocks to read a YAML file. For example, if you have a 250-word paragraph in a YAML file, you need to break the sentences into multiline blocks. You wouldn’t want to preserve the carriage returns except at the end of a paragraph. You can format a YAML file to use multiple lines for long strings and serialize the string to append spaces to each item instead of a new line character. 

To use a whitespace character instead of appending a new line, use the folded (“>”) operator:

    key: >




With the folded operator, YAML adds a space when it creates the string. The string looks like the following:

item1 item2 item3\n

YAML Multiline FAQs

How do you insert a line break in YAML?

Using the literal operator (“|”), any line breaks in a YAML string will be preserved. You create a line break using the carriage return keystroke in the same way that you create a line break in a standard document. The following example preserves the carriage return in a YAML string:

    key: |




Can YAML have blank lines?

Yes, a string represented as a block of text can also contain blank lines. The keep operator (“|+”)  preserves any blank empty lines along with the new line character. The following YAML is an example of a multiline string with two empty lines at the end of the block:

    key: |+




A YAML parser will display the following string from the above syntax:


Does YAML care about whitespace?

A tab whitespace is an illegal character in YAML, so any indents must be used with a standard single space character. Tabs can be used in quoted strings, but they cannot be used to format a YAML file. Consistency in whitespace indents is important for readability of data.

Are spaces allowed in YAML?

Yes, you can have standard spaces throughout a YAML file. Spaces should be used for indents and not the tab character. Tab characters could cause errors during the parsing of a YAML file.

Resources and Events
Pure//Accelerate® 2024

Join us June 18-21 and level up your data success.

Register Now
Optimise GenAI Apps with Retrieval-augmented Generation
7 min. read

Learn how Pure Storage is working with NVIDIA to help enterprises optimise their AI efforts.

Read the Blog
10 Ways Pure Helps You Uncomplicate Storage, Forever

Discover 10 ways Pure Storage® can help you uncomplicate storage, forever.

Read More
Reality Check On Storage as a Service and Evergreen//One
33 Min

Learn about Pure's Evergreen//One subscription offering and the white glove support we provide Evergreen//One customers.

Listen Now
Meet with an Expert

Let’s talk. Book a 1:1 meeting with one of our experts to discuss your specific needs.

Questions, Comments?

Have a question or comment about Pure products or certifications?  We’re here to help.

Schedule a Demo

Schedule a live demo and see for yourself how Pure can help transform your data into powerful outcomes. 

Call Sales: 800-976-6494


Pure Storage, Inc.

2555 Augustine Dr.

Santa Clara, CA 95054

800-379-7873 (general info)

Your Browser Is No Longer Supported!

Older browsers often represent security risks. In order to deliver the best possible experience when using our site, please update to any of these latest browsers.