DEV Community

Cassidy Williams
Cassidy Williams

Posted on • Originally published at blog.cassidoo.co

Making a single line break in markdown

Sometimes when you write markdown, you'll write some paragraph...

and then you hit "Enter" twice to make another paragraph.

Like this...

...and then this.
Enter fullscreen mode Exit fullscreen mode

This will render:

<p>Like this...</p>
<p>...and then this.</p>
Enter fullscreen mode Exit fullscreen mode

But, sometimes you want to make a single line break, kind of like in HTML where you have:

<p>
Like this... <br />
...and then this.
</p>
Enter fullscreen mode Exit fullscreen mode

In markdown, you can just drop in a <br /> and it'll work perfectly fine. But, if you want to keep your markdown HTML-less, you can add a backslash \ after your line, like so!

Like this...\
...and then this.
Enter fullscreen mode Exit fullscreen mode

This is supported in most markdown processors, but not all of them. Definitely check on the one you're using before you push to prod. Some processors also allow you to add a double space at the end of a line as well (truly just , hit your spacebar twice), but since a lot of code editor setups trim empty spaces, I personally prefer the backslash way.

Have

fun!

Top comments (4)

Collapse
 
tbroyer profile image
Thomas Broyer

Well, on DEV, every line break in source is a line break in output, so basically each paragraph must be on a single line. And I must say I hate this, I much prefer one sentence per line (friendlier to Git diff'ing, as I publish on GitHub Pages for my own blog then copy/paste to DEV for reach).

Collapse
 
cassidoo profile image
Cassidy Williams

DEV does support the double space one, though!

Collapse
 
tbroyer profile image
Thomas Broyer • Edited

Oh no it's way worse!

foo
bar
Enter fullscreen mode Exit fullscreen mode

without anything at the end of line, will turn into

<p>
foo<br>
bar
</p>
Enter fullscreen mode Exit fullscreen mode

I want it to be

<p>foo bar</p>
Enter fullscreen mode Exit fullscreen mode

And BTW, with the double space, it'll make two <br> โ€ผ

Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen

Nice!