536

How to add new line in Markdown presentation?

I mean, something like \newline in TeX.

14 Answers 14

548

Just add \ at the end of line. For example

one\
two

Will become

one
two

It's also better than two spaces because it's visible.

Edit:
It doesn't work in some markdown applications, so it may cause incompatibility. https://www.markdownguide.org/basic-syntax/#line-break-best-practices

8
  • 32
    I prefer this solution over the others because I have my IDE set to automatically trim extra whitespace at the end of a line. I don't want to turn that setting off just for this purpose, since it helps keep my code clean.
    – Calaway
    Oct 25, 2019 at 2:19
  • 9
    Jep, trailing whitespace as semantic meaning is just the biggest antipattern in code or docs :)
    – mark
    Mar 5, 2020 at 13:17
  • 4
    This doesn't actually work in markdown, sigh. I've seen it work in some renderers, but I don't know offhand which. What I do is write <space>\<space>. The \ quotes the second space and serves as a visual cue that I intend for there to be two spaces at the end. The problem is, there may not actually BE a space after the \, in which case it fails. But better than two invisible spaces. So often I go with <br />. I agree with @mark—biggest antipattern ever. Right up there with semantic tabs in old makefiles.
    – Bob Kerns
    Jul 3, 2020 at 7:23
  • 3
    Great!. It is in the CommonMark Specs
    – Madacol
    Aug 9, 2020 at 20:04
  • 3
    By the way, this is not recommended. markdownguide.org/basic-syntax/#line-break-best-practices
    – Pavel_K
    Apr 30, 2021 at 9:42
479

See the original markdown specification (bold mine):

The implication of the “one or more consecutive lines of text” rule is that Markdown supports “hard-wrapped” text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type’s “Convert Line Breaks” option) which translate every line break character in a paragraph into a <br /> tag.

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

7
  • 7
    Unfortunately, It doesnt work with headers... I would like to add break line (or just set bigger space) between the header and the rest of the slide.
    – max04
    Oct 18, 2015 at 10:25
  • 4
    @Mariusz, I don't know what presentation tool you are using, but assuming it's HTML-based I urge you to adjust the spacing with CSS. Markdown isn't concerned with design at all; it's all about content, and adding a blank line for spacing isn't a good semantic fit.
    – Chris
    Oct 18, 2015 at 12:56
  • 1
    What if I want a break line inside a table cell. I don't think this would work. Jun 10, 2020 at 13:32
  • @EduardoReis, tables aren't part of the original Markdown specification nor the widely-used Commonmark specification. Implementations that support them all have different rules and there are at least three widely-used table syntaxes. You can try using <br> in a table, but the result will depend entirely on the specific tool that you're using.
    – Chris
    Jun 10, 2020 at 13:45
  • @Chris, thanks for the clarification. I am using Pandoc. It confuses me that pandoc "works" with <br> if I am converting it to HTML. I guess it just keeps the <br> there and the browser does the job, sort of. But with the PDF format, it doesn't work. I tried other option, but none worked with pandoc, I might be missing a flag or something. Jun 10, 2020 at 13:49
163

How to add new line in Markdown presentation?

Check the following resource Line Return

To force a line return, place two empty spaces at the end of a line.

2
  • 6
    The issue with this is that I clear trailing whitespace from all files, which would break markdown files using this method. Jul 15, 2020 at 10:06
  • 5
    Then setup the trailing-space removal code to ignore markdown files. That's the language syntax, removing trailing-spaces in Markdown context is like removing semi-colons in PHP files. Or you can use @racoon_lord's solution. Mar 18, 2021 at 22:41
81

You could use &nbsp; in R markdown to create a new blank line.

For example, in your .Rmd file:

I want 3 new lines: 

&nbsp;
&nbsp;
&nbsp;

End of file. 
7
  • Can you explain why you think it's wrong? @user3441843 Sep 26, 2018 at 17:04
  • 1
    I think it's correct. The other answers are wrong (including the accepted answer) Sep 28, 2018 at 5:45
  • if you are using marked as the mardown render you should add breaks:true as option github.com/markedjs/marked/issues/835 Mar 14, 2019 at 1:26
  • 1
    Why does &nbsp; create a newline in R Markdown when it is the HTML code for inserting a non-breaking space? Dec 18, 2019 at 19:30
  • 1
    This works for me, when none of the other solutions have. It only seems able to insert 1 blank line though no matter how many times I copy and paste &nbsp;
    – C.Robin
    May 21, 2021 at 10:49
81

MarkDown file in three way to Break a Line

<br /> Tag Using

paragraph First Line <br /> Second Line

\ Using

First Line sentence \
Second Line sentence 

space keypress two times Using

First Line sentence␠␠
Second Line sentence

Paragraphs in use <br /> tag.

Multiple sentences in using \ or two times press space key then Enter and write a new sentence.

2
  • 2
    This should be marked as the updated correct solution as <br /> is the only solution here that worked in the Markdown implemented within StackExchange's UI. Nov 2, 2020 at 20:54
  • This is my personal favorite explanation. You have all of them listed and show clearly and simply.
    – Zach
    May 10 at 14:30
29

What worked for me

\
&nbsp;
\
&nbsp;

enter image description here

1
  • 3
    i just used &nbsp; didnt need the \
    – pelos
    Nov 3, 2021 at 15:23
19

Just add a \ in a new line and it will be fine.

\
2
  • This has already been mentioned in some of the other answers.
    – Eric Aya
    Jun 3, 2022 at 11:38
  • 3
    This was the answer that I needed. Nov 2, 2022 at 22:11
7

It depends on what kind of markdown parser you're using. For example in showdownjs there is an option {simpleLineBreaks: true} which gives corresponding html for the following md input:

a line
wrapped in two
<p>a line<br>
wrapped in two</p>
7

If none of the solutions mentions here work for you, which is what happened with me, then you can do the following: Add an empty header (A hack that ruins semantics)

text
####
text

Just make sure that when the header is added it has no border in bottom of it in the markdown css, so you can try different variations of the headers.

4

I was using Markwon for markdown parsing in Android. The following worked great:

"My first line  \nMy second line  \nMy third line  \nMy last line"

...two spaces followed by \n at the end of each line.

1
  • Wonderful solution for adding multiple lines of descriptions in NFT metadata. To be noted that <br /> would cause the description to disappear on platforms like Opensea. Oct 21, 2022 at 5:30
2

Neither a double space or \ at the end of a paragraph worked for me, however having a blank line between text in the code did, as did adding <p> at the start of the paragraph (having </p> at the end wasn't necessary)

    first paragraph

    second paragraph
    <p> first paragraph
    <p> second paragraph
0

You can also wrap it in a fenced code block. The advantage of this approach is you need not go for additional stuff for every line. However, the content shall be displayed as a highlighted block with a background, so it may not be apt for all use cases.

Lorem inmissa qui propinquas doleas
Accipe fuerat accipiam
0

As mentioned in other responses two spaces and enter will create a carriage return in markdown. The problem is your editor may trim that trailing whitespace. OP didn't mention a specific editor. In the case of VS Code you can suppress trimming on a per syntax basis in the settings.json file:

  "files.trimTrailingWhitespace": true,
  "[markdown]": {
    "files.trimTrailingWhitespace": false
  },
-6

The newline character (\n) can be used to add a newline into a markdown file programmatically. For example, it is possible to do like this in python:

with open("file_name.md", "w") as file:
   file.write("Some text")
   file.write("\n")
   file.write("Some other text")
1
  • This is a good answer since it gives the hint that \n\r does not work (esp. in C# UWP Markdown component). Only \n does the job.
    – E.S.
    Dec 31, 2019 at 0:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.