Ozgur
Ozgur

Reputation: 1844

Entering text in a TEXTAREA while keeping the formatting (just like the text in a PRE tag)

When I enter a text with line-breaks and long sentences, I don't want to see a wrapped or without line-breaks version. What is the CSS style to accomplish this? So far I tried white-space property but none gives the result I want.

Upvotes: 0

Views: 2122

Answers (2)

anon
anon

Reputation:

As @erik said, the way to do this is to use the wrap attribute on the tag itself, i.e.:

<textarea wrap="off"></textarea>

I just wanted to note, in case you're finicky about HTML validation, that the wrap property of textarea isn't part of any HTML standard.

Unfortunately, this is the only way to do this since the white-space CSS property, as you've discovered, doesn't work quite like you would expect when it comes to <textarea> elements.

Via Sitepoint:

Internet Explorer [...] The values normal and pre behave like pre-wrap on textarea elements. The value nowrap behaves like pre-line on textarea elements.

Firefox versions up to and including 3.0 don’t support the values pre-line and pre-wrap (although -moz-pre-wrap is similar to the latter). The values normal, nowrap, and pre behave like pre-wrap on textarea elements.

Opera 9.2 and prior versions don’t support the value pre-line. The values normal and pre behave like pre-wrap on textarea elements. The value nowrap behaves like pre-line on textarea elements.

Upvotes: 1

Erik
Erik

Reputation: 20722

You probably want the wrap attribute of the textarea tag. Have a look at this page: http://www.tizag.com/htmlT/htmltextarea.php

I'm not 100% sure what end result you want, but if you look at the options and explanations given via that link, you should be able to choose the one that fits your needs.

Upvotes: 3

Related Questions