Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping text inside input type="text" element HTML/CSS

The HTML shown below,

<input type="text"/>

is displayed in a browser like so:


When I add the following text,

The quick brown fox jumped over the lazy dog.

Using the HTML below,

<input type="text" value="The quick brown fox jumped over the lazy dog."/>

it is displayed in a browser like so:


But I would like it to be displayed in a browser like so:


I want the text in my input element to wrap. Can this be accomplished without a textarea?
like image 288
Web_Designer Avatar asked Oct 22 '22 12:10

Web_Designer


People also ask

Can we wrap text in input field?

You can't wrap text in a text input box, so perhaps you should use a textarea.

How do you wrap text in a text box?

Enable or disable text wrapping for a text box, rich text box, or expression box. Right-click the control for which you want to enable or disable text wrapping, and then click Control Properties on the shortcut menu. Click the Display tab. Select or clear the Wrap text check box.


1 Answers

That is the textarea's job - for multiline text input. The input won't do it; it wasn't designed to do it.

So use a textarea. Besides their visual differences, they are accessed via JavaScript the same way (use value property).

You can prevent newlines being entered via the input event and simply using a replace(/\n/g, '').

like image 190
alex Avatar answered Oct 24 '22 18:10

alex