HTML wrap Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Inputs

Introduction

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.

What You’ll Learn

01

soft

Default value.

02

hard

Submit breaks.

03

textarea

Only element.

04

cols

Wrap width hint.

05

Forms

Submit behavior.

06

JavaScript

.wrap property.

Purpose of wrap

The 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.

💡
Common misconception

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.

📝 Syntax

Add wrap to a <textarea> inside a form:

wrap.html
<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>

Syntax Rules

  • Valid only on <textarea>.
  • Values: soft (default) or hard.
  • Pair with cols so the browser knows the wrap width for hard.
  • User-entered Enter/Return line breaks are always included in both modes.
  • JavaScript: textarea.wrap = "hard" or setAttribute("wrap", "hard").
  • Visual styling: use CSS width, resize, and white-space.

💎 Values

The wrap attribute accepts two keyword values:

  • soft (default) — Text may wrap visually in the textarea, but when the form is submitted, the value contains only line breaks the user typed (Enter). Browser wrap points are not sent as newlines.
  • hard — Text also wraps visually, and when submitted, the value includes newline characters at each wrap boundary (in addition to user line breaks). Useful for fixed-width plain text.
wrap-values.html
<!-- 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>

⚡ Quick Reference

ValueVisual wrapSubmitted value
soft (default)Yes (via cols/CSS)User line breaks only
hardYes (via cols/CSS)User breaks + wrap breaks
Element<textarea> only
Helper attrcols defines wrap column count
JS propertyHTMLTextAreaElement.wrap

Applicable Elements

ElementSupported?Notes
<textarea>YesPrimary and only standard element for wrap
<input type="text">NoSingle-line; no wrap attribute
<div>, <p>NoUse CSS white-space and word-wrap

soft vs hard vs CSS wrapping

Featurewrap="soft"wrap="hard"CSS white-space
PurposeDefault submit behaviorInclude wrap newlinesVisual display only
Affects form submitYesYesNo
Where usedtextareatextareaAny element
Typical useComments, bios, chatPlain-text email styleLayout and readability

Examples Gallery

Try soft wrap in a form, compare hard wrap submission behavior, and toggle wrap with JavaScript.

👀 Live Preview

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

Example

Using wrap="soft" in an HTML form:

wrap.html
<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>

How It Works

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.

Example — hard wrap

When the server needs fixed-width plain text with line breaks preserved:

wrap-hard.html
<textarea name="comment" wrap="hard" rows="6" cols="50"></textarea>

How It Works

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.

Dynamic Values with JavaScript

Change wrap behavior at runtime:

dynamic-wrap.html
<textarea id="dynamicTextarea" rows="5" cols="30">
Type your text here...
</textarea>

<script>
  document.getElementById("dynamicTextarea").wrap = "hard";
</script>

How It Works

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.

♿ Accessibility

  • Always label textareas — Use <label for="..."> or aria-label; wrap does not describe purpose.
  • Do not rely on cols alone — Use CSS for readable width on all screen sizes.
  • Resize thoughtfully — CSS resize can help users who need a larger input area.
  • Instructions in visible text — If hard wrap affects expected format, explain it near the field.
  • Keyboard users — Enter still inserts line breaks in both soft and hard modes.

🧠 How wrap Works

1

User types text

In textarea.

Input
2

Text wraps visually

cols + CSS width.

Display
3

Form submits

soft or hard.

wrap
=

Value sent

With or without wrap breaks.

Browser Support

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.

Universal · textarea support

soft and hard in all major browsers

Verify hard-wrap submission in your stack when newline format is required.

100% Modern browsers
Google Chrome Supported
Supported
Mozilla Firefox Supported
Supported
Apple Safari Supported
Supported
Microsoft Edge Supported
Supported
wrap on textarea Excellent

Bottom line: Safe for production forms; test hard submit behavior if newline format is business-critical.

💡 Best Practices

✅ Do

  • Use default soft for most comment fields
  • Set cols when using hard
  • Label every textarea clearly
  • Use CSS for responsive width
  • Test submitted values in your backend

❌ Don’t

  • Assume hard disables visual wrapping
  • Assume soft blocks all automatic breaks on submit without testing
  • Use wrap on non-textarea elements
  • Rely on cols alone for mobile layout
  • Forget server-side validation of length and format
  • Consider content type and user experience when choosing between soft and hard.
  • Test forms across browsers if exact newline behavior matters.
  • Use wrap when you need to control text presentation in multiline form fields at submit time.

🎉 Conclusion

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.

Key Takeaways

Knowledge Unlocked

4 truths every developer should know about wrap

Bookmark these before your next wrap implementation.

4
Core concepts
📝 02

soft (default) omits browser

soft (default) omits browser wrap breaks from submitted data.

Syntax
⚙️ 03

hard includes newline characters

hard includes newline characters at wrap points on submit.

Usage
🔒 04

Visual wrapping is mainly

Visual wrapping is mainly controlled by cols and CSS, not by soft vs hard alone.

Dynamic

❓ Frequently Asked Questions

No. That is a common mistake. 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.
Yes, for predictable wrap columns. cols hints how many characters fit per line before a hard wrap break is inserted on submit.
No. Single-line inputs do not support wrap. Use textarea for multiline text.
CSS controls how text looks on screen. HTML wrap controls whether wrap points become newline characters in the submitted form value.

Practice textarea wrapping

Compare soft and hard wrap behavior in the live editor.

Try the soft wrap example →

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.

5 people found this page helpful