Skip to content

YAML Comments

Learn how YAML handles single-line comments, their limitations, and best practices for documenting code blocks without multi-line support.

YAML supports single line comments.

# This is a single line comment

YAML does not support multi line comments. But, if you want to provide comments for multiple lines, you can use single line comments in this way:

# This is a comment line 1
# This is a comment line 2
# This is a comment line 3

Features of Comments

  • A commented block is skipped during execution.
  • Comments help to add a description to specified block of code.
  • Comments must not appear inside scalars.
  • YAML does not provide any way to escape the hash symbol (#) a within multiline string, so there is no way to divide the comment from the raw value of the string.

For example, comments within a collection are made in this way:

key: #comment 1
- value 1
- value 2
- value line 3
Navigation