HTML wrap Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The wrap attribute on a <textarea> controls how the control prepares its value for form submission. Use soft (default) or hard.

With hard, the browser inserts line breaks so each line fits the control width — you must also set cols. Pair with rows, name, and a proper <label>.

Baseline · Widely available.

Not deprecated and not experimental. Standard soft / hard values on modern browsers.

Non-standard: wrap="off".

Some browsers treat off like soft with horizontal scrolling (white-space: pre). Prefer soft or hard for portable HTML.

HTML Syntax

syntax.html
<textarea wrap=" soft | hard" cols="n"> … </textarea>

Default is soft when omitted. For hard, cols is required.

Attribute Values

Standard keywords and the common non-standard option:

ValueDescriptionTry it
soft (default)No extra wrap breaks in the submitted valueTry it
hardInsert CR+LF so lines fit the width; needs colsTry it
(omitted)Same as softTry it
offNon-standard — often no visual wrap; horizontal scrollTry it

Live Preview

Switch wrap, type a long line, then Submit to see whether hard wrap adds breaks in the submitted string.

wrap

hard needs cols. Submit to inspect the value (↵ shown for line breaks).

textarea

wrap="soft" · submitted value appears here

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Default soft Wrap

Most comment boxes use soft wrap (or omit the attribute).

HTML
<label for="comment">Comment:</label>
<textarea
  id="comment"
  name="comment"
  rows="4"
  cols="40"
  wrap="soft"></textarea>
Try It Yourself

How It Works

  1. wrap="soft" is the default if you omit the attribute.
  2. No auto breaks are inserted for form submission based on width.
  3. Label + id keep the control accessible.
  4. cols / rows still set visible size; they do not force hard wrap alone.

Example 2 — hard Wrap Needs cols

Use hard wrap when the server should receive line-broken plain text at a fixed width.

HTML
<label for="notes">Notes (hard wrap):</label>
<textarea
  id="notes"
  name="notes"
  rows="5"
  cols="20"
  wrap="hard"></textarea>
Try It Yourself

How It Works

  1. wrap="hard" asks the browser to insert CR+LF for form data.
  2. cols="20" is required — it defines the wrap width.
  3. Breaks appear in the submitted value, not necessarily as new Enter keys while typing.
  4. Use when backends expect fixed-width plain text lines.

Example 3 — Compare Soft and Hard on Submit

Same long text; hard adds wrap breaks you can inspect after submit.

HTML
<form id="wrap-demo">
  <label>Soft
    <textarea name="soft" rows="3" cols="20" wrap="soft">ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</textarea>
  </label>
  <label>Hard
    <textarea name="hard" rows="3" cols="20" wrap="hard">ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</textarea>
  </label>
  <button type="submit">Check values</button>
</form>
<pre id="out"></pre>

<script>
  document.getElementById("wrap-demo").addEventListener("submit", function (e) {
    e.preventDefault();
    var data = new FormData(this);
    function show(v) {
      return String(v).replace(/\r\n/g, "↵").replace(/\n/g, "↵");
    }
    document.getElementById("out").textContent =
      "soft: " + show(data.get("soft")) + "\n" +
      "hard: " + show(data.get("hard"));
  });
</script>
Try It Yourself

How It Works

  1. Same characters in both fields for a fair comparison.
  2. FormData reads what would be submitted for each name.
  3. hard may include wrap ↵ markers; soft usually stays one continuous string.
  4. Open Try It Yourself to edit the text and re-test.

Edge Cases & Pitfalls

Most confusion is mixing visual wrapping with the submitted string, or forgetting cols for hard wrap.

hard

Always set cols with hard

Without cols, wrap="hard" is invalid. Soft wrap does not require it.

submit

About form data, not CSS

wrap is not a substitute for CSS white-space or overflow-wrap on other elements.

non-standard

off is not portable

Stick to soft and hard for cross-browser HTML. Use CSS if you need a no-wrap look.

js

Reading .value

In script, textarea.value is the live contents. Hard wrap breaks are applied for submission (and FormData), which you can demonstrate by submitting a form.

a11y

Keep a real label

wrap does not replace <label>, placeholder, or required.

Browser Support

wrap is an HTML attribute on <textarea>. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

wrap

soft and hard are widely supported. Prefer those two keywords; treat wrap="off" as non-standard where you encounter it.

96% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer Supported
Supported
wrap Widely supported

Bottom line: Safe for everyday forms. Use soft by default; use hard with cols when the server needs fixed-width line breaks.

Key Takeaways

  • Role: how textarea values wrap for form submission.
  • Default: soft — no auto wrap breaks.
  • hard: insert line breaks; always set cols.
  • Avoid: relying on non-standard off in new pages.

One line: wrap is about submitted textarea line breaks — soft by default, hard with cols when you need fixed-width breaks.

Frequently Asked Questions

On a textarea, wrap controls how the value is prepared for form submission. soft (default) does not insert extra line breaks. hard inserts CR+LF breaks so each line fits the control width.
soft keeps the typed value as-is (normalizing existing line breaks to CR+LF) without adding wrap breaks. hard automatically inserts line breaks based on the visible width, which requires the cols attribute.
Hard wrap needs a known column width to decide where to insert breaks. The HTML specification requires cols when wrap is hard.
soft and hard mainly affect the submitted string. Visual wrapping while editing is mostly browser/CSS behavior. The non-standard off value (where supported) can make long lines scroll horizontally instead of wrapping.
No. The living HTML Standard defines soft and hard. off appears in some browser docs and MDN as a practical value, but treat it as non-standard.
No. soft and hard are standard, Baseline, and widely available on textarea.

Next: xmlns

XML namespace on the document root for XHTML/XML.

xmlns tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful