Poetry in Markdown: Keeping Stanza Breaks and Indentation Intact
To keep a poem's shape in Markdown, end every line except the last in a stanza with a backslash, leave a blank line between stanzas, and use where a line needs indenting. If the layout has to be exact, a fenced code block keeps everything as typed.
This goes wrong most often with poems shared as Valentine's cards, letters or posts. You type them line by line, and the preview shows one long paragraph. Below are poetry in Markdown line breaks with real examples, and they work the same way in any CommonMark-based editor. For a wider look at the syntax, see our Markdown cheat sheet.
Why poem lines run together
In Markdown, a paragraph is one or more consecutive lines of text, separated by one or more blank lines. A single newline inside it is not a line break. The CommonMark spec calls it a soft line break, and a renderer may show it as a line ending or as a space.
So this poem:
Roses are red
Violets are blue
Sugar is sweet
And so are youcan render as Roses are red Violets are blue Sugar is sweet And so are you. Your file is fine. That's just how paragraphs work, and we cover the general case in why Markdown text runs together.
Hard breaks: backslash or two spaces
A hard line break forces the line to end where you ended it. CommonMark gives you two ways to write one.
Trailing spaces
Two or more spaces before the line ending make a break. The original Markdown syntax describes it the same way: end a line with two or more spaces, then press return. It works, but you can't see the spaces. An editor that trims trailing whitespace will quietly remove them.
Backslash
In CommonMark, a backslash at the end of the line is a hard line break. It's visible in the source, so you can see at a glance which lines are protected, and it survives whitespace trimming. For poems, we prefer it.
The last line of a stanza
Neither syntax works at the end of a block. The CommonMark spec is explicit that a break on the last line of a paragraph produces nothing, so the final line of a stanza needs no marker. The blank line after it separates the stanzas:
Roses are red\
Violets are blue\
Sugar is sweet\
And so are you
I wrote this down\
so I would not forget\
the way you laughed\
the first time we metEach stanza renders as its own paragraph, with every line on its own line. Any text editor that opens plain .md files will show the same result, because the file itself carries the structure.
Indenting poem lines
Many poems indent a line to show a pause or a turn. Plain spaces won't do it: in CommonMark, leading spaces on a paragraph's continuation lines are skipped, so this indentation disappears:
The tide goes out\
and comes back inUse non-breaking space entities instead. CommonMark renders as a non-breaking space, and it needs the semicolon. Without it, the text is not recognized as an entity and shows up literally:
The tide goes out\
and comes back inFour entities give a short indent. Two limits to know about: character references are not recognized inside code spans or code blocks, so this only works in normal paragraph text, and a long row of entities makes the source harder to read.
The fenced code block fallback
When a poem depends on exact spacing, such as a shaped poem or a deep stagger, put it in a fenced code block. The GFM spec says a fenced code block may interrupt a paragraph and needs no blank line before or after it. Everything inside is kept as typed: spaces, tabs and line breaks. Backslashes and entities are not processed.
The trade-off is how it looks. Code blocks display in monospace, and you lose emphasis and links inside the poem. Use it when layout matters more than typography.
Pandoc line blocks
If you convert your files with Pandoc, it has a syntax built for this. In the Pandoc manual, a line block is a sequence of lines beginning with a vertical bar and a space, and the division into lines is preserved, as are any leading spaces:
| The tide goes out
| and comes back inInline formatting such as emphasis still works inside a line. This is a Pandoc extension, not part of CommonMark or GFM, so most previews will show the vertical bars as text. Use it only when your whole toolchain is Pandoc.
Check the preview before you share it
Renderers differ in small ways, and a card is hard to fix once it's sent. Look at the rendered result, not just the source, before you share a poem. If you are writing something personal, writing a love letter in plain text walks through line breaks and printing as well.
How Carets fits in
Carets is a native notes and code editor for iPhone, iPad and Mac. It handles Markdown, plain text and code in one place. For poetry, that means you can write in plain .md files, where backslash breaks and indents are ordinary characters you can see and edit. Because your files stay plain text, a poem written today opens in any other editor later with its structure intact. You can also keep poems together in a project and label them with tags, so a collection of drafts stays organized.
Get Carets on the App Store for iPhone, iPad and Mac.
Frequently Asked Questions
How do I keep line breaks in a poem in Markdown?
End every line except the last in a stanza with a backslash, or with two or more spaces, and leave a blank line between stanzas. The last line of each block needs no marker.
Why doesn't my last line need a backslash?
CommonMark does not turn a break at the end of a paragraph into a line break, so a marker there does nothing. The blank line after the line already separates the stanza from the next one.
How do I indent a poem line in Markdown?
Leading spaces on a continuation line are skipped, so use entities, a fenced code block, or a Pandoc line block if your tools support it.
Is a code block a good way to keep a poem's layout?
It keeps every space and line break, but the poem shows in monospace and emphasis is not processed. Use it when exact layout matters more than appearance.