How to insert a line break <br> in markdown

Learn how to insert a line break
in markdown with practical examples, diagrams, and best practices. Covers markdown development techniques with visual explanations.

Mastering Line Breaks in Markdown: The
Tag and Beyond

Hero image for How to insert a line break <br> in markdown

Learn how to effectively insert line breaks in Markdown, understanding the nuances of the <br> tag, trailing spaces, and their rendering across different platforms.

Markdown is a lightweight markup language that allows you to format plain text. While it's excellent for readability and simplicity, inserting a simple line break can sometimes be less straightforward than expected. This article will guide you through the various methods to achieve line breaks in Markdown, focusing on the HTML <br> tag, trailing spaces, and their implications for different Markdown renderers.

The HTML <br> Tag: Universal Line Break

The most reliable and universally supported method for inserting a line break in Markdown is to use the HTML <br> tag directly. Markdown is designed to be a superset of HTML, meaning you can embed raw HTML within your Markdown documents, and most renderers will process it correctly. This method ensures that a line break occurs exactly where you place the tag, regardless of the Markdown flavor or platform.

This is the first line.<br>
This is the second line, forced by `<br>`.

Another paragraph starts here.

Using the HTML <br> tag for a guaranteed line break.

Trailing Spaces: The Markdown Way

Many Markdown specifications, including CommonMark, define that two or more spaces at the end of a line, followed by a newline character, should render as a hard line break. This is often considered the 'Markdown way' to insert a line break without resorting to HTML. However, its rendering can be inconsistent across different Markdown processors, as some might ignore trailing spaces or require specific configurations.

This line ends with two spaces.  
This line should appear directly below the first.

This is a new paragraph.

Using two trailing spaces for a line break (behavior may vary).

flowchart TD
    A[Start Markdown Rendering] --> B{Line Ends with Two Spaces?}
    B -->|Yes| C[Insert Hard Line Break]
    B -->|No| D{Line Followed by Blank Line?}
    D -->|Yes| E[Start New Paragraph]
    D -->|No| F[Continue on Same Line (Soft Wrap)]
    C --> G[Render Content]
    E --> G
    F --> G

Decision process for line breaks in Markdown renderers.

Blank Lines: Paragraph Separation

It's crucial to distinguish between a line break and a new paragraph. In Markdown, a blank line (a line containing only spaces or nothing at all) between two lines of text will always render as a new paragraph. This introduces more vertical space than a simple line break and is the standard way to separate distinct blocks of text.

This is the first paragraph.

This is the second paragraph, separated by a blank line.

Using a blank line to create a new paragraph.

Choosing the Right Method

The best method for inserting a line break depends on your specific needs and the environment where your Markdown will be rendered. If universal compatibility and precise control are paramount, the <br> tag is your safest bet. If you prefer a more 'Markdown-native' approach and are confident in your renderer's support, trailing spaces can be used. For standard paragraph separation, simply use a blank line.

1. Identify Your Need

Determine if you need a hard line break (minimal vertical space) or a new paragraph (more vertical space).

2. For Hard Line Breaks

Use <br> for guaranteed results, or two trailing spaces followed by a newline for a Markdown-native approach (test for compatibility).

3. For New Paragraphs

Always use a blank line between blocks of text to create distinct paragraphs.

4. Test Your Markdown

Render your Markdown on the target platform or viewer to ensure the line breaks appear as intended.