4

I want to insert a line break into my profile text on a website, which only allows text to be inserted, so I can not use any html tag.

I would like to know if there in any way to insert line break just like inserting spaces or tabs using ASCII codes?

rkb
  • 514
  • 2
  • 9
  • 19
  • 2
    The text is probably encoded before it is saved at the server, which means you can't write what ever you want and it will still display just like you wrote it on your profile page. – kaspermoerch Feb 21 '14 at 10:20

8 Answers8

8

You can set the white-space to pre-line - this will then respect carriage returns.

p {
    white-space: pre-line;
}
<p>Hello,\r\nGoodbye!</p>

Will render:

Hello,
Goodbye!
Steven Peirce
  • 498
  • 7
  • 10
4

I think you are looking for codes like '&nbsp;' and so...
The 'carry return' code is '&#13;'

Maybe what you are looking for is in there: ASCII HTML CODES

aNGRoN
  • 63
  • 5
  • This didn't help me with an HTML question, but for a regular text entry that wasn't formatting properly. Thank you! – parker_codes Aug 15 '17 at 17:34
3

There isn’t. You can enter e.g. a LINE FEED character as &#10;, but it won’t help: by HTML rules, it will still be taken just as yet another whitespace character, and any sequence of whitespace characters is equivalent to one SPACE in normal HTML content. You cannot override the HTML rules for processing characters by the characters themselves (only by HTML markup or by CSS).

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
1

You probably can't add an arbitrary line break. However, you can influence where a line break occurs if the text is to be rendered inside a container that is not long enough to display the text as a single line. Just use non-breaking spaces at the right places in the text.

Let's suppose the text contains sentences and it is going to be broken to several lines and you want a line break to occur before a certain sentence. Then use non-breaking spaces instead of regular spaces in the sentence. The specific sentence will then possibly not fit on the current line and will be rendered on a new line:

The text is to be rendered in this box. Let's force a line break now.
This•text•starts•on•a•new•line as it will not fit on the previous line without breaking the text
(• stands for &nbsp;).
Weaver
  • 568
  • 4
  • 5
  • 1
    This is clever! The only gotcha is to make sure that the "word" (all the text connected by ` `'s) is long enough to not fit on the previous line, but not longer than the full width of the line (otherwise depending on `word-break` property it'll either overflow or might break in an arbitrary spot in the middle of a word). This is easy in many cases but if the container is responsive over a big range of widths then it might not be possible. – tobek Jul 22 '19 at 13:35
1

You can use the <pre> tag when sending the email. Inside this tag textual line breaks are shown as actual line breaks in html.

<p>
  this is a 
  text with 
  line breaks
</p>
<pre>
this is a 
text with
line breaks
</pre>
Shiran Dror
  • 1,472
  • 1
  • 23
  • 36
0

In mailto body, this created a new line without any issues: %0D

-1

Try \n just after from where you want to break the line.

wpercy
  • 9,636
  • 4
  • 33
  • 45
Deo
  • 82
  • 5
-3

You and anyone else reading this can use this probably

%0A
wpercy
  • 9,636
  • 4
  • 33
  • 45
J-T
  • 9
  • 5