HTML Textarea horizontal scroll

HtmlTextareaWord Wrap

Html Problem Overview


I would like to provide a horizontal scroll to a textarea in my HTML page. The scroll should appear without wrapping, if I type a long line without a line break. A few friends suggested using overflow-y CSS attribute, which did not work for me. The browsers that I use are IE 6+ and Mozilla 3+.

Html Solutions


Solution 1 - Html

I figured out to do it in a non-W3c-compliant way and it is working in both IE and Firefox and incidentally in Chrome too.

I added the attribute wrap with value off, that is <textarea cols=80 rows=12 wrap='off'> is what I have done.

Solution 2 - Html

To set no wrapping, you would use:

white-space: nowrap;

For other values: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

NOTE: However the depreciated wrap="off" seems to be the only way for legacy browser support. Though it isn't HTML 5 compliant, it's still my preference if you're targeting all browsers.

Solution 3 - Html

If you have pre-formatted text that includes LFs, you should add white-space: pre; to the css. That will preserve the new lines that are already in the text and will not wrap long lines.

This works in all versions of Firefox, all Webkit-based browsers, and IE6+.

Source: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

Solution 4 - Html

Try these:

overflow: scroll; 
overflow-y: scroll; 
overflow-x: scroll; 
overflow:-moz-scrollbars-vertical;

there should also be a -moz-scrollbars-horizontal

Solution 5 - Html

Use white-space: pre; as CSS property.

https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShyam Kumar SundarakumarView Question on Stackoverflow
Solution 1 - HtmlShyam Kumar SundarakumarView Answer on Stackoverflow
Solution 2 - HtmlAram KocharyanView Answer on Stackoverflow
Solution 3 - HtmlazdleView Answer on Stackoverflow
Solution 4 - HtmlFilip EkbergView Answer on Stackoverflow
Solution 5 - HtmlchtenbView Answer on Stackoverflow