wrap
Control how textarea content wraps and how line breaks are submitted with form data. Affects both visual display and the actual value sent to the server.
Overview
The wrap attribute on <textarea> controls two things: whether text wraps visually in the textarea, and whether the browser inserts line breaks into the submitted form value at wrap points.
Applies to: <textarea>
Values
| Value | Visual Wrap | Line Breaks in Submission | Notes |
|---|---|---|---|
soft (default) | Yes | No | Most common; wraps for display only |
hard | Yes | Yes (\r\n inserted) | Requires cols attribute |
off | No | No | Horizontal scroll for long lines |
Soft Wrap (Default)
Text wraps visually at the textarea boundary, but the submitted value contains only the line breaks the user explicitly typed. This is the default and appropriate for most text input.
Hard Wrap
Text wraps visually and the browser inserts \r\n characters at each visual wrap point in the submitted value. The cols attribute is required — it determines the column width where wrapping occurs.
Key detail: The hard value actually changes the form data. If your server does not expect these inserted line breaks, they may cause formatting issues in stored text.
No Wrap
Text does not wrap at all. Long lines extend beyond the visible area and the textarea scrolls horizontally. This is ideal for code editing or any content where line breaks are semantically meaningful.
How Submission Differs
The critical distinction between soft and hard is in the submitted form data, not the visual appearance. Both look the same to the user.
Practical Form Example
Different wrap values suit different types of content within the same form.
Accessibility
- The
wrapattribute does not affect screen reader behavior. The text content is read the same regardless of the wrap setting. - When using
wrap="off", ensure the textarea is wide enough to show meaningful content without scrolling. Horizontal scrolling is harder to discover for keyboard-only users. - Always pair
<textarea>with a visible<label>regardless of the wrap setting.
Limitations
wrap="hard"does nothing without thecolsattribute. Ifcolsis missing, the browser treats it assoft.- The
colsattribute uses character units, which do not account for variable-width fonts. The actual visual wrap point may not align precisely with the column count. - The
wrapattribute is not widely known. Many developers use CSSwhite-spaceandoverflowinstead, though those do not affect form submission data. wrap="off"is not officially in the HTML spec (it was in HTML4 but dropped from HTML5). All major browsers still support it, butsoftwith CSSwhite-space: preis the standards-compliant alternative.
See Also
<textarea>— the textarea elementdisabled— prevent interaction with form controlsreadonly— non-editable but still submitteddirname— submit text directionality alongside the value