HTML cols Attribute

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

Definition and Usage

The cols attribute on a <textarea> sets its visible width in average character widths (character columns). If omitted, the default is 20.

Pair it with rows for height, a proper <label>, and optionally wrap. For fluid layouts, CSS width / max-width can override or complement cols.

Baseline · Widely available.

Not deprecated and not experimental. Standard <textarea> sizing attribute across modern browsers.

HTML Syntax

syntax.html
<textarea cols=" positive-integer"> … </textarea>

Value must be a positive integer (character columns). Initial text goes between the tags, not in a value attribute.

Attribute Values

How common cols values behave:

ValueDescriptionTry it
(omitted)Default visible width is 20 columnsTry it
30, 40, …Positive integer — wider visible controlTry it
With rowsSet width and height together for consistent sizingTry it
With wrap="hard"cols is required so hard wrap can insert line breaksTry it

Live Preview

Change cols and watch the textarea’s visible width update. Typing length is not limited by cols.

Visible width only. Use maxlength if you need a character limit.

textarea

cols="30"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Basic cols

Give a comment box a clear visible width with a labeled control.

HTML
<label for="feedback">Your feedback:</label>
<textarea id="feedback" name="feedback" cols="40"></textarea>
Try It Yourself

How It Works

  1. cols="40" sets the visible width to roughly 40 character columns.
  2. Label + id keeps the control accessible for screen readers and clicks.
  3. Empty body means no default text; users start with a blank field.
  4. Not a max length. Users can still type past the visible width (scroll / wrap).

Example 2 — cols with rows

Set width and height together so browser defaults do not surprise you.

HTML
<label for="story">Tell us your story:</label>
<textarea id="story" name="story" rows="5" cols="33">
It was a dark and stormy night...
</textarea>
Try It Yourself

How It Works

  1. rows="5" shows five lines of text height.
  2. cols="33" sets the visible character width.
  3. Default content sits between the opening and closing tags.
  4. Consistency. Explicit size beats relying on each browser’s default.

Example 3 — wrap="hard" needs cols

Hard wrap inserts line breaks on submit so lines fit the control width — cols is required.

HTML
<label for="notes">Notes (hard wrap):</label>
<textarea
  id="notes"
  name="notes"
  rows="4"
  cols="40"
  wrap="hard"></textarea>
Try It Yourself

How It Works

  1. wrap="hard" asks the browser to insert line breaks for submission.
  2. cols must be set so the browser knows the target line width.
  3. soft (default) does not add extra breaks — only normalizes existing ones.
  4. See wrap for the full list of wrap values and behavior.

Edge Cases & Pitfalls

Most surprises come from treating cols as a character limit or ignoring CSS layout.

limit

Not a maxlength

cols only affects visible width. Cap length with maxlength (and validate on the server).

CSS

CSS width can override

Stylesheets often set width: 100%. Then cols may not match what you see. Use both intentionally.

resize

Users can resize the box

Most browsers show a resize handle. CSS resize controls that — independent of cols.

wrap

hard wrap requires cols

Without cols, wrap="hard" cannot apply the intended line width for submission.

naming

Not colspan

colspan spans table cells. cols sizes a textarea. Different attributes.

Browser Support

cols is an HTML attribute for <textarea> in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

cols

Widely available with textarea across modern browsers. Default width is 20 columns when the attribute is omitted.

96% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer Supported
Supported
cols Widely supported

Bottom line: Safe to use for character-based textarea sizing. Combine with CSS when you need responsive layouts.

Key Takeaways

  • Role: visible textarea width in average character columns.
  • Default: 20 when omitted; value must be a positive integer.
  • Pair with: rows, and set cols when using wrap="hard".
  • Not a limit: use maxlength (and server checks) to cap input.

One line: cols sizes the textarea’s visible width — it does not limit typed characters.

Frequently Asked Questions

On a textarea, cols sets the visible width in average character widths (character columns). It does not limit how much text the user can type.
In modern HTML, cols applies to textarea. (Legacy frameset also had a cols attribute for frame layout — that is obsolete and separate.)
If you omit cols, the default visible width is 20 character columns.
A positive integer, such as 30 or 50. Zero or negative values are invalid.
cols sets width in character columns; rows sets the number of visible text lines. Setting both keeps sizing more consistent across browsers.
If wrap="hard", the browser inserts line breaks so each line fits the control width — and cols must be specified for that wrapping to take effect.

Next: colspan

Span a table cell across multiple columns.

colspan 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