HTML rows Attribute

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

Definition and Usage

The rows attribute on <textarea> sets how many visible text lines the control shows. If you specify it, the value must be a positive integer. If you omit it, the default is 2.

Pair it with cols (visible width in average character widths; default 20) for a consistent starting size across browsers. Always use a proper <label>.

Baseline · Widely available.

Not deprecated. Size hint only — it does not limit typed text. Not the same as table rowspan.

HTML Syntax

syntax.html
<textarea rows=" positive_integer">…</textarea>
<textarea rows=" n" cols="m">…</textarea>

In JavaScript: textarea.rows = 5. Initial text goes between the tags, not in a value attribute.

Attribute Values

One positive integer — visible line count:

ValueDescriptionTry it
(omitted)Default visible height: 2 linesTry it
rows="n"Show about n lines (n ≥ 1)Try it
rows + colsHeight and width together for a stable boxTry it
rowspan (tables)Different attribute — cell spans table rowsTry it

Live Preview

Change rows and apply. The box grows or shrinks in visible lines — typing length is unchanged.

Default without the attribute is 2. Users may still resize the control unless CSS sets resize: none.

Textarea

rows: 4

HTML Examples

Short demos. Use Try It Yourself for a live editor.

Example 1 — Basic rows

Give a feedback box a taller visible area than the default two lines.

HTML
<label for="feedback">Feedback</label>
<textarea id="feedback" name="feedback" rows="5"></textarea>
Try It Yourself

How It Works

  1. rows="5" asks for about five visible lines.
  2. Default without rows would be two lines.
  3. Label is tied with for / id for accessibility.
  4. Typing limit is separate — add maxlength if needed.

Example 2 — rows with cols

Set both dimensions so browser defaults do not surprise you.

HTML
<label for="story">Your story</label>
<textarea id="story" name="story" rows="6" cols="40">
It was a dark and stormy night…
</textarea>
Try It Yourself

How It Works

  1. rows ≈ visible height in lines.
  2. cols ≈ visible width in average characters (default 20).
  3. Content between tags is the starting text.
  4. CSS can still refine layout; attributes give a solid baseline.

Example 3 — rows ≠ rowspan

Textareas use rows. Table cells that span vertically use rowspan.

HTML
<!-- textarea height -->
<textarea rows="3" cols="24">Notes</textarea>

<!-- table cell spanning two rows -->
<table border="1">
  <tr>
    <td rowspan="2">A</td>
    <td>B</td>
  </tr>
  <tr><td>C</td></tr>
</table>
Try It Yourself

How It Works

  1. rows = textarea visible lines.
  2. rowspan = how many table rows a cell covers.
  3. Similar names — different elements and jobs.
  4. Next topic rowspan covers table spanning in depth.

Edge Cases & Pitfalls

Most mistakes are treating rows as a text limit or confusing it with tables.

value

Must be a positive integer

Invalid or missing values fall back to browser defaults (typically 2 lines).

limit

Not a character cap

Use maxlength / minlength for length rules.

css

CSS and resize can change the box

Users may drag the corner; resize: none disables that. height can override the attribute visually.

tables

Not rowspan

Table spanning is a different attribute on td / th.

a11y

Always label the control

Placeholders are not a substitute for a visible <label>.

Browser Support

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

✓ Baseline · Widely available

rows

Supported everywhere modern forms work. Setting rows (and cols) avoids inconsistent browser defaults.

98% Global support (approx.)
Google Chrome Yes
Full support
Mozilla Firefox Yes
Full support
Apple Safari Yes
Full support
Microsoft Edge Yes
Full support
Opera Yes
Full support
Samsung Internet Yes
Full support
Internet Explorer Yes
Supported
rows Widely supported

Bottom line: Safe to use. Prefer explicit rows + cols, then refine with CSS if needed.

Key Takeaways

  • Role: visible line count on <textarea> (default 2).
  • Pair with cols for a predictable starting size.
  • Not a text limit — use maxlength for that.
  • Not rowspan — that is for tables.

One line: rows sets how many lines tall a textarea appears.

Frequently Asked Questions

On a textarea, rows sets how many lines of text are visible. If omitted, the default is 2. The value must be a positive integer when specified.
The textarea element. It is not for tables — table cells use rowspan to span multiple rows.
rows is the visible height in lines. cols is the visible width in average character widths (default 20). Use both for a predictable starting size.
No. It only affects the visible size. Use maxlength / minlength for length limits, or CSS for layout.
Yes. A CSS height (or resize by the user) can change the rendered size. Still set rows for a sensible default before styles apply.
No. It is a Baseline widely available attribute on textarea.

Next: rowspan

Span a table cell across multiple rows with rowspan.

rowspan 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