HTML rows Attribute

Beginner
⏱️ 4 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Validation

Introduction

The rows attribute sets the visible height of a <textarea> in text lines. Use it to give users enough space for comments, feedback, or longer messages without relying on CSS alone. The default is 2 rows if you omit the attribute. Pair rows with cols for both height and width, or use CSS min-height for responsive layouts. Set textarea.rows in JavaScript to resize dynamically. Not the same as rowspan on table cells.

What You’ll Learn

01

Text lines

Visible height.

02

textarea

Only element.

03

+ cols

Width & height.

04

Default 2

If omitted.

05

.rows

JS property.

06

vs rowspan

Not tables.

Purpose of rows Attribute

The primary purpose of rows is to define how many lines of text are visible at once in a textarea. It sets the initial vertical size of the field so users can see more (or less) content before scrolling.

A contact form might use rows="4" for a short note and rows="10" for a detailed support ticket. Users can still type beyond the visible area — the field scrolls — but a well-chosen rows value improves the first impression of your form.

💡
rows vs cols

rows controls visible height in lines. cols controls visible width in character columns. Use both on the same <textarea> for a balanced default size. See the cols attribute guide.

📝 Syntax

Add rows to a <textarea> with a positive integer:

rows.html
<label for="comments">Comments:</label>
<textarea id="comments" name="comments" rows="5"></textarea>

Syntax Rules

  • Valid only on <textarea> elements.
  • Value must be a positive integer (e.g. 3, 8, 12).
  • Default is 2 when the attribute is omitted.
  • Controls initial visible lines — users can scroll to see more typed content.
  • Pair with cols for width; use CSS for responsive sizing.
  • JavaScript: textareaElement.rows = 10 (integer property).
  • Not related to rowspan on <td> / <th>.

💎 Values

The rows attribute accepts a positive integer representing visible text lines:

  • rows="2" — Default size; fine for one-line notes.
  • rows="4" — Short feedback or comment fields.
  • rows="8" — Medium messages, support requests.
  • rows="12" or higher — Long-form text, drafts, descriptions.
rows-values.html
<textarea rows="3" cols="30">Short comment</textarea>
<textarea rows="6" cols="40">Standard message</textarea>
<textarea rows="12" cols="60">Long description</textarea>

How it Works

In rows="5", the browser renders the textarea tall enough to show approximately five lines of text at the default font size.

⚡ Quick Reference

Use Caserows ValueNotes
Quick noterows="2"HTML default
Contact commentrows="4"Common form size
Support ticketrows="8"More visible space
Article body draftrows="12"+Long-form writing
Width controlcols="40"Pair with rows
Applicable element<textarea>Not input or table

Applicable Elements

ElementSupports rows?Notes
<textarea>YesPrimary and standard use
<input>NoSingle-line only — use CSS height if needed
<td>, <th>NoUse rowspan for table cell merging
<div>Norows is not a global height attribute

rows vs rowspan

Aspectrows on textarearowspan on table cells
Element<textarea><td>, <th>
PurposeVisible height in linesMerge cells vertically
ValueLine count (e.g. 8)Number of rows spanned (e.g. 2)
ContextFormsHTML tables
JavaScripttextarea.rowscell.rowSpan (camelCase)

Examples Gallery

Form textarea sizing, dynamic textarea.rows in JavaScript, and comparing different row counts side by side.

👀 Live Preview

Comments field with rows="5" and cols="40":

Example — Form with rows

Give users a taller area for comments in a simple form:

rows-form.html
<form>
  <label for="comments">Comments:</label>
  <textarea id="comments" name="comments" rows="8"></textarea>
  <input type="submit" value="Submit">
</form>
Try It Yourself

How It Works

rows="8" makes the textarea tall enough to show about eight lines before the user needs to scroll.

Dynamic Values with JavaScript

Adjust visible height programmatically with the rows property:

dynamic-rows.html
<textarea id="dynamicTextArea"></textarea>

<script>
  document.getElementById("dynamicTextArea").rows = 10;
</script>
Try It Yourself

How It Works

textarea.rows accepts a positive integer. Useful when expanding a field after the user selects “Add more details” or similar.

Example — Compare row sizes

Same width, different rows values:

rows-compare.html
<label>Short (3 rows)</label>
<textarea rows="3" cols="40"></textarea>

<label>Tall (10 rows)</label>
<textarea rows="10" cols="40"></textarea>
Try It Yourself

How It Works

Choose rows based on how much text you expect. Short fields feel compact; taller fields invite longer responses.

♿ Accessibility

  • Always use labels — Pair every <textarea> with a visible <label> linked via for/id.
  • Size is visual only — Screen readers do not treat rows as a character or line limit.
  • Allow resizing when helpful — CSS resize: vertical lets users grow the field if they need more space.
  • Do not use rows as validation — Use maxlength or server checks for input limits, not visible height.
  • Test on mobile — Large rows values can dominate small screens; balance with CSS max-height.

🧠 How rows Works

1

Set rows on textarea

Author picks visible line count in HTML.

Markup
2

Browser sets height

Line height × rows ≈ field height.

Layout
3

User types content

Scroll appears when text exceeds visible lines.

Input
=

Better multiline UX

Users see an appropriately sized writing area.

Browser Support

The rows attribute is supported in all modern browsers on <textarea> elements.

HTML5 · Fully supported

Universal textarea height

All major browsers honor rows for default textarea height.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
rows on textarea Excellent

Bottom line: Safe to use for textarea height in all modern browsers.

💡 Best Practices

✅ Do

  • Match rows to expected content length (short note vs long essay)
  • Pair with cols or CSS width for a balanced textarea
  • Use resize: vertical in CSS so users can expand if needed
  • Combine with placeholder and maxlength for clear form UX
  • Read the <textarea> tag guide for full element behavior

❌ Don’t

  • Confuse rows with rowspan on table cells
  • Put rows on <input> — it has no effect
  • Use tiny rows="1" when users need multiline input
  • Rely on rows alone for responsive design — add CSS
  • Assume rows limits how much users can type — it only affects visible height

Conclusion

The rows attribute is a simple, effective way to set the initial visible height of a <textarea> in lines of text.

Choose a value that fits your form’s purpose, pair it with cols or CSS for width, and use textarea.rows in JavaScript when you need dynamic sizing.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about rows

Bookmark these when building forms.

5
Core concepts
📈 02

Line height

Visible rows.

Effect
🔢 03

Default 2

If omitted.

Default
🔧 04

+ cols

Width too.

Pair
🚫 05

Not rowspan

Tables differ.

Gotcha

❓ Frequently Asked Questions

It sets how many lines of text are visible in a <textarea> — the initial height of the field.
If you omit rows, the default is 2 visible lines.
No. rows sizes a textarea. rowspan merges table cells vertically — completely different.
document.getElementById("myArea").rows = 10; — assign a positive integer to the rows property.
No. It only controls visible height. Users can type more and scroll. Use maxlength to cap character count.
Yes. All modern browsers support rows on <textarea>.

Size your textareas with rows

Set visible line count on <textarea> so forms feel right for the amount of text you expect.

Try it yourself →

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