References

Beginner-friendly references for web development, with live, editable examples.

The HTML wrap attribute

Attribute All modern browsers
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 wrap is soft or hard, so you can't see the setting by looking at the field. Check the submitted request instead.
  • The breaks that hard inserts appear in the submitted data and in new FormData(form), but not in textarea.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.value uses 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 honor off, which isn't a valid keyword but stops wrapping on screen, and Chrome reads physical and on as 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?
Use the rows and cols attributes, or set its width and height with CSS.
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.