<textarea wrap="">

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
Attribute of
HTML5 Textarea Attributes: Here's What You Should Know
What does <textarea wrap=""> do?
Determines whether or not submitted text wraps when a <textarea> is included in a form submission.

Forcing Newlines in a Submitted Textarea

The wrap attribute is used to tell the browser whether or not to add newlines when a form is submitted so that the text is wrapped at a defined width. There are two possible values used with the wrap attribute: soft and hard. If the soft value is used, no newlines will be added to the submitted value. If the hard value is used a newline character (a character entity) will be added after the number of characters indicated in the cols attribute. For example, when the text area below was submitted a newline would be added after ever 40 characters.

<textarea cols="40" wrap="hard"></textarea> <style>   textarea {     width: 100%;   } </style> 

CSS is often used to control the rendering or presentation of a textarea. However, regardless of how the textarea is presented visually in a browser, the newline characters will be added on the basis of where the cols attribute dictates they should be added. So, when we render the textarea above with the CSS width property set to 100% it displays at the full width of the parent element. However, when submitted, a carriage return would be added after every 20 characters.

Adam is a technical writer who specializes in developer documentation and tutorials.