Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make newline chars visible in HTML textarea?

I want to make newline (CR and LF) characters visible in a textarea field of an HTML form, as you can do in some text editors and IDEs. The user needs to be able to edit the text to insert newlines as well (i.e. create paragraph breaks), which should also show dynamically. Is there a way to do this?

TIA....

Steve

like image 843
user522401 Avatar asked Jan 06 '11 14:01

user522401


People also ask

How do I preserve line breaks when getting text from a textarea?

If you want your text to overflow the parent's boundaries, you should use pre as your CSS whitespace property. Using white-space: pre wraps still preserves newlines and spaces.

How do you show line breaks in HTML?

To add a line break to your HTML code, you use the <br> tag. The <br> tag does not have an end tag. You can also add additional lines between paragraphs by using the <br> tags.

Which character defines a new line in the textarea?

Talking specifically about textareas in web forms, for all textareas, on all platforms, \r\n will work.

Is textarea block or inline?

<textarea> is a replaced element — it has intrinsic dimensions, like a raster image. By default, its display value is inline-block .


1 Answers

The only way to do this is to print out your own marker characters before/after each line break, using javascript.

The character reference for the pilcrow (¶) character is &#x00B6;.

like image 172
Oded Avatar answered Oct 24 '22 13:10

Oded