425

When editing an issue and clicking Preview the following markdown source:

a
b
c

shows every letter on a new line.

However, it seems to me that pushing similar markdown source structure in README.md joins all the letters on one line.

I'd like the new lines preserved in the README.md in this project: https://github.com/zoran119/simple-read-only-test

Any idea how?

zcoop98
  • 2,590
  • 1
  • 18
  • 31
zoran119
  • 10,657
  • 12
  • 46
  • 88
  • 1
    Does this answer your question? [How to insert a line break
    in markdown](https://stackoverflow.com/questions/26626256/how-to-insert-a-line-break-br-in-markdown)
    – Michael Freidgeim Dec 25 '22 at 12:39
  • I cannot understand why people don't want to be allowed to break lines of code without breaking lines visually. It is just like being against html consuming extra space or treating newlines as spaces. Specially if you are talking about github. GitHub uses diff... it is horrible to have a very long line!!! So... I am forced to write a whole paragraph in one line... :-( – André Caldas May 12 '23 at 12:10

6 Answers6

836

Interpreting newlines as <br /> used to be a feature of Github-flavored markdown, but the most recent help document no longer lists this feature.

Fortunately, you can do it manually. The easiest way is to ensure that each line ends with two spaces. So, change

a
b
c

into

a__
b__
c

(where _ is a blank space).

Or, you can add explicit <br /> tags.

a <br />
b <br />
c
tbekolay
  • 17,201
  • 3
  • 40
  • 38
  • 3
    Thank you so much. My documents will be much better now! – Guilherme Ferreira Aug 29 '16 at 16:20
  • 3
    according to https://stackoverflow.com/questions/18019957/where-is-github-flavored-markdown-gfm-actually-used-in-github Github-favored markdown is not used everywhere on Github. Might be outdated though. – Ben Creasy Mar 18 '17 at 22:48
  • Gracias mi amigo! – Ev. Oct 29 '17 at 12:23
  • According to the link you give, it's now possible to create line breaks "by leaving a blank line between lines of text." There is still a problem: with this method, you create a new paragraph, not just a line break. – Pierre Oct 28 '18 at 15:30
  • 1
    As @BenCreasy said, Github-flavored markdown is not used in README.md files. Or, to be fair, not the full set of features is used: syntax highlighting and auto-linking URLs are available; hard line breaks, formatted task lists and references to issues—aren’t. – Dato Jan 25 '19 at 08:10
  • 5
    Forward slash doesn't seem to be necessary, worked fine with just
    – user3015682 Aug 24 '19 at 23:03
  • The forward slash sounds like a workaround but works well instead the html tag already is a formal way to do the task. Thanks so much @tbekolay! your answer helps me a lot. – Thiago Valentim Jan 04 '20 at 21:48
  • I tried it for Bitbucket and the only format that worked were the 2 blank spaces. Anything else (
    ,
    , Backslash) didn't work.
    – Manuel Oct 05 '20 at 14:41
  • works well for me, but 2 spaces are not working for me (GitHub README.md file). – Evgeniy Tishin Nov 16 '21 at 12:15
86

You can use a backslash at the end of a line.
So this:

a\
b\
c

will then look like:

a
b
c

Notice that there is no backslash at the end of the last line (after the 'c' character).

m13r
  • 2,458
  • 2
  • 29
  • 39
Waldmann
  • 1,563
  • 12
  • 25
8

You should use html break <br/> tag

a <br/>
b <br/>
c

Raj K
  • 568
  • 6
  • 11
5

If you want to be a little bit fancier you can also create it as an html list to create something like bullets or numbers using ul or ol.

<ul>
<li>Line 1</li>
<li>Line 2</li>
</ul>
Switch900
  • 161
  • 2
  • 5
2

Using the mentioned methods above didn't work for me in all cases.

I ended up adding "##" to add a new line!

a
##
b
##
c
-1

According to Github API two empty lines are a new paragraph (same as here in stackoverflow)

You can test it with http://prose.io

bgauryy
  • 416
  • 3
  • 7