502

How to add new line in Markdown presentation?

I mean, something like \newline in TeX.

poke
  • 369,085
  • 72
  • 557
  • 602
max04
  • 5,315
  • 3
  • 13
  • 21

14 Answers14

496

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
  • 5,065
  • 1
  • 7
  • 7
  • 31
    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
  • 9
    Jep, trailing whitespace as semantic meaning is just the biggest antipattern in code or docs :) – mark Mar 05 '20 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 \. 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
  • 3
    Great!. It is in the [CommonMark Specs](https://spec.commonmark.org/0.29/#hard-line-breaks) – Madacol Aug 09 '20 at 20:04
  • 3
    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
  • @Pavel_K But most Linters don't like inline html. So its either: - Trailing whitespaces (*nobody* likes them, i hope...) - Ignoring Recomendations - Ignoring Linters – Booker B Feb 18 '22 at 11:50
  • 2
    This is a good solution and it works in nearly all places. But as of June 2022, it doesn't work on the Bitbucket website, when it displays markdown files or "Issues" bug reports (which are also markdown files). Bitbucket files must use the 'two empty spaces at end of line' method instead. – Mr-IDE Jun 02 '22 at 13:40
  • 1
    @Pavel_K, "not recommended" according to who? Is anybody authoritative behind that website? CommonMark is the closest thing we have to a universal Markdown spec and, as Madacol notes above, CommonMark includes this behaviour. Sure, there are tools that behave differently, but they're all so different from each other that you might as well restrict yourself to what's in the [original implementation](https://daringfireball.net/projects/markdown/syntax) at that point. Unfortunately, the original version is not fully specified. – ChrisGPT was on strike Mar 24 '23 at 18:13
470

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
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 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 '15 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. – ChrisGPT was on strike Oct 18 '15 at 12:56
  • 1
    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.
    – ChrisGPT was on strike 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. – ChrisGPT was on strike Jun 10 '20 at 14:04
  • This reminds me of https://en.wikipedia.org/wiki/Whitespace_(programming_language) . – jochen Nov 25 '22 at 07:54
159

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,896
  • 2
  • 19
  • 28
  • 6
    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
  • 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. – Kamafeather Mar 18 '21 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. 
77

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
  • 1,857
  • 2
  • 14
  • 21
  • 2
    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.
    – AdamHurwitz Nov 02 '20 at 20:54
  • This is my personal favorite explanation. You have all of them listed and show clearly and simply. – Zach May 10 '23 at 14:30
28

What worked for me

\
&nbsp;
\
&nbsp;

enter image description here

Alex Punnen
  • 5,287
  • 3
  • 59
  • 71
17

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

\
Michael Chao
  • 570
  • 5
  • 14
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>
daGo
  • 2,584
  • 26
  • 24
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.

ehab
  • 7,162
  • 1
  • 25
  • 30
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.

Tom Howard
  • 4,672
  • 2
  • 43
  • 48
  • Wonderful solution for adding multiple lines of descriptions in NFT metadata. To be noted that `
    ` would cause the description to disappear on platforms like Opensea.
    – Terry Windwalker Oct 21 '22 at 05: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
obs
  • 43
  • 7
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
Srichandradeep C
  • 387
  • 2
  • 13
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
  },
JDH
  • 2,618
  • 5
  • 38
  • 48
-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")
  • 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