HTML rows Attribute

The HTML rows attribute specifies the number of visible text lines displayed by a <textarea> control. It provides an initial height for the text area without limiting how much text the user can enter.

Elements That Use the rows Attribute

The rows attribute is used with the <textarea> element.

Element Description
<textarea> Specifies the number of visible text lines for the multiline text control.

rows Value

The value of the rows attribute must be an integer greater than zero. The number represents the visible character height of the <textarea> in text lines.

<textarea rows="5"></textarea>

In this example, the text area is displayed with an initial height of five visible lines.

How rows Works

The rows attribute provides the browser with the expected visible height of a <textarea>. Increasing the value generally makes the control taller, while decreasing it makes the control shorter.

<label for="message">Message:</label>
<textarea id="message" name="message" rows="6"></textarea>

The rows value affects the displayed size of the control, not the amount of text it can contain. Users can enter more lines than are visible, and the control can scroll when necessary.

Default Value

If the rows attribute is omitted, the default character height of a <textarea> is 2.

<textarea name="comments"></textarea>

If a specified rows value cannot be parsed as an integer greater than zero, the text area's character height also falls back to 2.

Using rows with cols

The rows and cols attributes are commonly used together to provide the initial dimensions of a <textarea>. The rows attribute controls its character height, while cols controls its character width.

<textarea name="comments" rows="5" cols="40"></textarea>

This example provides space for approximately five visible lines with a character width based on 40 columns.

rows and CSS

The rows attribute provides an intrinsic or preferred starting size for the <textarea>. CSS can also control the rendered dimensions of the control and can override the size that would otherwise result from the HTML attributes.

<textarea name="message" rows="5"></textarea>
textarea {
  height: 150px;
}

Use rows when the number of visible text lines is meaningful to the form, and use CSS when the design requires more precise control over the rendered dimensions.

Common Mistakes

Do not use zero or a negative number for rows. The attribute requires an integer greater than zero.

Do not use rows to limit how many lines of text a user can enter. It controls the visible height of the <textarea>, not the amount of content it can contain.

Do not confuse rows with cols. The rows attribute controls the character height, while cols controls the character width.

Do not assume that the user cannot resize the text area. Browsers commonly allow <textarea> controls to be resized unless CSS changes that behavior.

Browser Support

Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.

The rows attribute on the <textarea> element is widely supported in current core browsers.

Checking Browser Support

For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.

Try the rows Attribute

The example shows two text areas with different rows values so you can compare their initial visible heights.

Play in Editor

Summary

The HTML rows attribute specifies the visible character height of a <textarea> control in text lines. Its value must be an integer greater than zero, and the default character height is 2 when a valid value is not specified. The attribute controls the initial visible size of the control rather than limiting how much text the user can enter.