The HTML wrap attribute
In short
The HTML wrap attribute controls how line breaks are handled in the submitted value. It is used on the <textarea> element.
Overview
The wrap attribute controls how line breaks are handled in the submitted value. It applies to the <textarea> element.
With hard you must also set cols; the browser then inserts real line breaks at wrap points in the submitted text.
Syntax
<textarea wrap="hard" cols="20"></textarea>
Values
| Value |
|---|
| soft (default) | hard |
Best practices
- Long lines wrap on screen the same way whether
wrapis soft or hard, so you can't see the setting by looking at the field. Check the submitted request instead. - The breaks that
hardinserts appear in the submitted data and innew FormData(form), but not intextarea.value. maxlength ignores them, so the submitted text can be longer than its limit. - Every line break in a submitted textarea reaches the server as a CRLF pair, with soft as well as hard, even though
textarea.valueuses a bare LF. Normalize line endings on the server before you compare or count characters. - The keyword ignores letter case, and the standard reads a missing or unknown value such as
wrap="true"as soft. Browsers also honoroff, which isn't a valid keyword but stops wrapping on screen, and Chrome readsphysicalandonas hard. - Don't parse the submitted lines as fixed-width fields. The standard leaves the break points to each browser, and Chrome follows the field's rendered width, so CSS sizing can move them.
Frequently asked questions
What does the wrap attribute do?
Controls textarea line wrapping on submit.
How do I set the size of a textarea?
What is the difference between soft and hard wrap?
In hard mode, wrap has the browser add line breaks to the submitted text, aiming at the cols width. Soft, the default, adds no line breaks of its own.
Which elements use the wrap attribute?
It is an element-specific attribute, used on the <textarea> element.























