Skip to content Skip to sidebar Skip to footer

How Can I Add Line Break To Html Text Without Using Any Html Tag

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 i

Solution 1:

There isn’t. You can enter e.g. a LINE FEED character as 
, 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).


Solution 2:

I think you are looking for codes like ' ' and so...
The 'carry return' code is '
'

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


Solution 3:

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!

Solution 4:

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;).

Solution 5:

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>

Post a Comment for "How Can I Add Line Break To Html Text Without Using Any Html Tag"