Markdown Paragraphs and Line Breaks to HTML

Understand how Markdown handles paragraphs and line breaks when converting to HTML. Learn the difference between soft breaks, hard breaks, and paragraph separation.

Block Elements

Detailed Explanation

Paragraphs and Line Breaks in Markdown

Markdown handles whitespace differently from HTML. Understanding paragraph and line break rules is critical for producing correctly formatted HTML output.

Paragraphs

In Markdown, paragraphs are separated by one or more blank lines. A single block of text without blank lines is rendered as a single <p> element:

This is the first paragraph.

This is the second paragraph.

Converts to:

<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>

Line Breaks (Hard Breaks)

To create a line break (<br>) within a paragraph, end a line with two or more spaces before pressing Enter, or use a backslash (\) at the end of the line:

First line with two trailing spaces
Second line in the same paragraph

First line with backslash\
Second line in the same paragraph

Both produce:

<p>First line with two trailing spaces<br>
Second line in the same paragraph</p>

Soft Breaks

A single newline in Markdown (without trailing spaces) is treated as a soft break and is usually collapsed into a single space in the HTML output:

These two lines
become one paragraph.

Renders as:

<p>These two lines
become one paragraph.</p>

Most browsers display this as a continuous sentence. Some Markdown parsers offer a "hard wrap" mode where every newline becomes a <br>, but this is not standard behavior.

Common Pitfalls

  • Forgetting the blank line between paragraphs results in a single <p> tag.
  • Trailing spaces for line breaks are invisible and easy to miss — consider using the backslash syntax instead.

Use Case

Correctly handling paragraphs and line breaks is fundamental when converting Markdown to HTML for blog posts, email templates, and documentation. Misunderstanding these rules often leads to text running together or unexpected spacing in the rendered output.

Try It — Markdown to HTML Converter

Open full tool