MikeSwanson
MikeSwanson

Reputation: 497

Can I make an <input> box have text that wraps?

I have an

<input type="text" /> 

box. The data in my box is quite long so I set the height to 100px. However the text just goes from left to right and does not wrap. Is there any way I could make it wrap?

Hoping for some good suggestions.

Thanks,

Upvotes: 10

Views: 31788

Answers (4)

Raghav
Raghav

Reputation: 3058

With the style attr, or with CSS, you can do this:

<textarea 
    id="temp" 
    style="white-space: pre-wrap; height: 100px; width: 500px;"
>This is my text box. And it can wrap.</textarea>

The same thing can be done in jQuery with:

$('#dom_id').attr("style", "white-space: pre-wrap");

This will hold for both textbox and text area.

Upvotes: 0

Isaac Truett
Isaac Truett

Reputation: 8884

No, you can't make an input element do that. Use textarea instead.

Upvotes: 3

H&#229;vard S
H&#229;vard S

Reputation: 23876

For multiline input and wrapping text, use a <textarea>.

Upvotes: 5

mellamokb
mellamokb

Reputation: 56769

You need to use a <textarea> instead for input text that wraps.

Upvotes: 15

Related Questions