👀 Live Preview
A textarea with default wrap="soft" (cols controls width hint):

The wrap attribute is used on the <textarea> element to control how line breaks are handled when the form is submitted. It does not replace CSS for visual layout; it affects the string sent to the server.
When users type long lines in a textarea, text may wrap visually at the edge of the box. The question is: should those automatic wrap points become real newline characters in the submitted value? That is what soft and hard decide.
Default value.
Submit breaks.
Only element.
Wrap width hint.
Submit behavior.
.wrap property.
wrapThe main purpose of the wrap attribute is to define whether the browser should insert newline characters at wrap points when a textarea value is submitted. This gives you control over plain-text formatting on the server side.
For most modern apps, soft (the default) is fine because servers and APIs handle long lines without requiring fixed-width line breaks. Use hard when you need email-style or fixed-column plain text with breaks preserved.
hard does not turn off visual wrapping, and soft does not mean “only wrap when the user presses Enter.” Both values can show wrapped text. The difference is whether wrap points become line breaks in the submitted value.
Add wrap to a <textarea> inside a form:
<form>
<label for="message">Your Message:</label>
<textarea id="message" name="message" wrap="soft" rows="4" cols="30"></textarea>
<input type="submit" value="Submit">
</form><textarea>.soft (default) or hard.cols so the browser knows the wrap width for hard.textarea.wrap = "hard" or setAttribute("wrap", "hard").width, resize, and white-space.The wrap attribute accepts two keyword values:
<!-- Default: soft -->
<textarea name="bio" rows="4" cols="40"></textarea>
<!-- Explicit hard wrap on submit -->
<textarea name="comment" wrap="hard" rows="6" cols="50"></textarea>| Value | Visual wrap | Submitted value |
|---|---|---|
soft (default) | Yes (via cols/CSS) | User line breaks only |
hard | Yes (via cols/CSS) | User breaks + wrap breaks |
| Element | <textarea> only | |
| Helper attr | cols defines wrap column count | |
| JS property | HTMLTextAreaElement.wrap | |
| Element | Supported? | Notes |
|---|---|---|
<textarea> | Yes | Primary and only standard element for wrap |
<input type="text"> | No | Single-line; no wrap attribute |
<div>, <p> | No | Use CSS white-space and word-wrap |
soft vs hard vs CSS wrapping| Feature | wrap="soft" | wrap="hard" | CSS white-space |
|---|---|---|---|
| Purpose | Default submit behavior | Include wrap newlines | Visual display only |
| Affects form submit | Yes | Yes | No |
| Where used | textarea | textarea | Any element |
| Typical use | Comments, bios, chat | Plain-text email style | Layout and readability |
Try soft wrap in a form, compare hard wrap submission behavior, and toggle wrap with JavaScript.
A textarea with default wrap="soft" (cols controls width hint):
Using wrap="soft" in an HTML form:
<form>
<label for="message">Your Message:</label>
<textarea id="message" name="message" wrap="soft" rows="4" cols="30"></textarea>
<input type="submit" value="Submit">
</form>With wrap="soft", long lines wrap visually inside the box, but only Enter key line breaks appear in the data sent when the form submits. This is the right default for most comment fields and contact forms.
When the server needs fixed-width plain text with line breaks preserved:
<textarea name="comment" wrap="hard" rows="6" cols="50"></textarea>wrap="hard" tells the browser to insert newline characters at wrap points in the submitted string. Set cols so wrap boundaries are predictable. Test in your target browsers if submission format is critical.
Change wrap behavior at runtime:
<textarea id="dynamicTextarea" rows="5" cols="30">
Type your text here...
</textarea>
<script>
document.getElementById("dynamicTextarea").wrap = "hard";
</script>The wrap IDL property accepts "soft" or "hard". You can switch modes when the user picks a format (plain text vs free-form) or when validation rules change.
<label for="..."> or aria-label; wrap does not describe purpose.resize can help users who need a larger input area.In textarea.
cols + CSS width.
soft or hard.
With or without wrap breaks.
The wrap attribute is well supported on <textarea> in all modern browsers. Behavior is most predictable when cols is set for hard wrap. Test form submission if exact newline formatting matters.
Verify hard-wrap submission in your stack when newline format is required.
Bottom line: Safe for production forms; test hard submit behavior if newline format is business-critical.
soft for most comment fieldscols when using hardhard disables visual wrappingsoft blocks all automatic breaks on submit without testingwrap on non-textarea elementscols alone for mobile layoutsoft and hard.wrap when you need to control text presentation in multiline form fields at submit time.The wrap attribute gives you control over newline handling in textarea form submission. For everyday forms, soft is usually enough. Choose hard when the server expects plain text with line breaks at fixed wrap columns.
Combine wrap with proper labels, CSS layout, and validation to build clear, accessible multiline inputs.
wrapBookmark these before your next wrap implementation.
wrap applies only to <textarea>.
soft (default) omits browser wrap breaks from submitted data.
hard includes newline characters at wrap points on submit.
Visual wrapping is mainly controlled by cols and CSS, not by soft vs hard alone.
hard adds line breaks at automatic wrap points when the form is submitted. Users can still press Enter for manual line breaks in both modes.soft. If you omit the attribute, the browser treats the textarea as soft wrap.cols hints how many characters fit per line before a hard wrap break is inserted on submit.wrap. Use textarea for multiline text.wrap controls whether wrap points become newline characters in the submitted form value.Compare soft and hard wrap behavior in the live editor.
5 people found this page helpful