39

How do I do a single newline/carriage return when typing a question or answer?

For example, if I wanted to write some columns with values as in an Excel spreadsheet. I see people do it all the time, but I don't know how. I read the formatting tips and all about the blockquote stuff... did some google'ing, but I still haven't found out how.

The only way I know to do newlines is by pressing the Enter key twice, which makes a new paragraph, creating an empty line, which is not what I want.

migrated from stackoverflow.com Jul 5 '12 at 15:46

This question came from our site for professional and enthusiast programmers.

  • 3
    Did you already try <br/> like in HTML? – TimVK Jun 20 '12 at 12:27
  • Thanks Tim. <br/> works ! I didn't think of that one. I can use shift+enter here for newlines, but when asking a question or answering one I have to use <br/> tags. Okay. got it. edit: You can put that solution in as an answer so it can be voted on. Respectfully, Josh – joshpt Jun 20 '12 at 12:33
  • I find that sometimes <br> is needed too, depending on the situation – joshpt Jun 20 '12 at 12:42
  • So it looks like that meta part of the site deals with questions pertaining to mechanics of the stackoverflow site itself. Please correct me if it is anything different or anything more. – joshpt Jun 21 '12 at 19:47
  • 1
    Beware of the small screens, where such tables do not have scrollbars but are wrapped. – Arjan Jul 5 '12 at 16:51
  • 1
    Related: balpha wrote a long answer to a related question explaining why the two-line rule exists. – Pops Sep 20 '12 at 17:28
  • 2
    hit Spacebar twice. then Enter – Arpit Rawat Sep 20 '12 at 17:59
  • As u useful comment was wiped when other answers to this question were deleted, let me repeat one very good reason not to use <br>: <br/> creates formatting messes later for someone trying to go back and edit to clean up other things (say, by applying a <pre> tag -- suddenly all that markup is visible), and it's the harder way to do this anyway. – Joel Coehoorn♦ Jul 5 '12 at 16:05 – Arjan Aug 17 '13 at 8:24
63

You can type two spaces    and press Enter.
Like so.

I wanted to write some columns with values as in an Excel spreadsheet

For longer/pasted text, you can also format as code in many ways, like by indenting with 4 spaces, or by using <pre></pre> tags (which need manual encoding of HTML), like so:

Column 1   Column 2   Column 3
value 1      13            26
value 2      11            22
  • 4
    But as an aside: line breaks should not be confused with (or abused for) paragraphs. – Arjan Jul 25 '12 at 9:34
  • 1
    @gobernador, Why not use <br> instead? – Pacerier Apr 5 '15 at 11:29
  • Is that useful? of no use – kdh Apr 30 '15 at 5:40
  • @kdh, I mean typing <br> instead of typing "space" + "space" + "newline". Try it, it works. – Pacerier Jul 15 '15 at 1:42
  • @Pacerier as Pops said in a comment to a now deleted answer, "Markdown should be preferred over HTML" - which makes sense. Raw HTML should be used with care and only when there's no Markdown alternative. – Shadow The Dragon Wizard Jul 15 '15 at 7:30
  • @ShadowWizard, That's true only if a future CSS template might display them differently. However, <br> and "space" + "space" + "newline" are synonymous regardless of styling. – Pacerier Aug 5 '15 at 9:22
  • testing the new line now <br> my new line – Automationtested Jun 6 '17 at 5:54
  • test<br> it works really ? – j10 Sep 28 '17 at 6:37
  • @jitenshah: HTML tags don't work in comments, only in posts. There's no way that I know of to insert line breaks in comments (except for MathJax hacks on sites that have it enabled). – Ilmari Karonen Oct 31 '17 at 19:24
3

use the HTML line break tag '<br>', see example below where Line 1 uses the line break & line 2 uses the Enter key.

Example (1: <br>, 2: Enter)

Line 1
Line 2 Line 3


Click the 'edit' button on this posting here for good reference.

  • 1
    That works, but there are already three deleted answers suggesting that, all with negative scores. People don't like HTML when there's a Markdown solution :) – Glorfindel Oct 31 '17 at 18:44
  • The two spaces + enter is a lot more elegant, especially in markdown view. I'm sure there's times (and spaces) for html, but doublespacing what I recommend. – Journeyman Geek Nov 1 '17 at 2:57
  • 2
    For me, this answer is useful. – sancho.s Feb 22 at 7:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .