216

How to add new line in Markdown presentation?

I mean, something like \newline in TeX.

poke
  • 307,619
  • 61
  • 472
  • 533
max04
  • 2,375
  • 2
  • 10
  • 17

11 Answers11

244

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.

Community
  • 1
  • 1
Chris
  • 93,263
  • 50
  • 204
  • 189
  • 2
    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 '15 at 10:25
  • 2
    @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 '15 at 12:56
  • What if I want a break line inside a table cell. I don't think this would work. – Eduardo Reis Jun 10 '20 at 13:32
  • @EduardoReis, tables aren't part of [the original Markdown specification](https://daringfireball.net/projects/markdown/syntax) nor the widely-used [Commonmark specification](https://spec.commonmark.org/current/). Implementations that support them all have different rules and there are at least three widely-used table syntaxes. You can try using `
    ` in a table, but the result will depend entirely on the specific tool that you're using.
    – Chris Jun 10 '20 at 13:45
  • @Chris, thanks for the clarification. I am using Pandoc. It confuses me that pandoc "works" with `
    ` if I am converting it to HTML. I guess it just keeps the `
    ` 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.
    – Eduardo Reis Jun 10 '20 at 13:49
  • Yes, that's exactly what it does. You might be able to get it working in your PDF with ``\\``, but that won't work in HTML :-). There's probably already a question about line breaks in tables from Markdown using Pandoc, but if you can't find one feel free to ask a new one. – Chris Jun 10 '20 at 14:04
127

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

racoon_lord
  • 1,372
  • 1
  • 3
  • 7
  • 11
    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 '19 at 02:19
  • 2
    Easily the best solution for this quetsion! – s_om Dec 06 '19 at 07:25
  • 3
    Jep, trailing whitespace as semantic meaning is just the biggest antipattern in code or docs :) – mark Mar 05 '20 at 13:17
  • 1
    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 \. 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
    . I agree with @mark—biggest antipattern ever. Right up there with semantic tabs in old makefiles.
    – Bob Kerns Jul 03 '20 at 07:23
  • 2
    Great!. It is in the [CommonMark Specs](https://spec.commonmark.org/0.29/#hard-line-breaks) – Madacol Aug 09 '20 at 20:04
  • By the way, this is not recommended. https://www.markdownguide.org/basic-syntax/#line-break-best-practices – Pavel_K Apr 30 '21 at 09:42
122

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.

Romulo
  • 4,323
  • 2
  • 17
  • 25
  • 2
    The issue with this is that I clear trailing whitespace from all files, which would break markdown files using this method. – Matt Fletcher Jul 15 '20 at 10:06
  • 1
    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. – Kamafeather Mar 18 '21 at 22:41
50

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. 
  • Can you explain why you think it's wrong? @user3441843 – Summer Jinyu Xia Sep 26 '18 at 17:04
  • 1
    I think it's correct. The other answers are wrong (including the accepted answer) – user3441843 Sep 28 '18 at 05:45
  • if you are using marked as the mardown render you should add breaks:true as option https://github.com/markedjs/marked/issues/835 – John Balvin Arias Mar 14 '19 at 01:26
  • @user3441843, what's wrong with the accepted answer? – Chris Sep 07 '19 at 20:00
  • 1
    Why does ` ` create a newline in R Markdown when it is the HTML code for inserting a [non-breaking space](https://www.w3schools.com/html/html_entities.asp)? – HelloGoodbye Dec 18 '19 at 19:30
  • @HelloGoodbye its not that ` ` is creating the _new line_ but it's fooling the parser that would normally truncate consecutive blank lines, so this is putting a whitespace character on each line, so the line is no longer zero length. – Chris Schaller Oct 14 '20 at 23:45
  • 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 ` ` – C.Robin May 21 '21 at 10:49
34

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.

Vishal Vaghasiya
  • 864
  • 1
  • 7
  • 15
  • This should be marked as the updated correct solution as `
    ` is the only solution here that worked in the Markdown implemented within StackExchange's UI.
    – Adam Hurwitz Nov 02 '20 at 20:54
5

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>
daGo
  • 1,601
  • 16
  • 21
4

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.

ehab
  • 3,608
  • 13
  • 21
3

What worked for me

\
&nbsp;
\
&nbsp;

enter image description here

Alex Punnen
  • 3,420
  • 36
  • 52
1

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.

Tom Howard
  • 3,876
  • 1
  • 35
  • 43
0

I wanted to create a MarkdownPreviewer in react as part of a project in freecodecamp. So I was desperately searching for newline characters for markdown. After trying many suggestions. I finally used \n and it worked.

Nidhi
  • 1
-3

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")
  • 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 '19 at 00:31