HTML cols Attribute

Definition
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.
Syntax
HTML Syntax
<textarea cols=" positive-integer"> … </textarea>
Value must be a positive integer (character columns). Initial text goes between the tags, not in a value attribute.
Values
Attribute Values
How common cols values behave:
| Value | Description | Try it |
|---|
| (omitted) | Default visible width is 20 columns | Try it |
30, 40, … | Positive integer — wider visible control | Try it |
With rows | Set width and height together for consistent sizing | Try it |
With wrap="hard" | cols is required so hard wrap can insert line breaks | Try it |
Try it
Live Preview
Change cols and watch the textarea’s visible width update. Typing length is not limited by cols.
Code
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.
<label for="feedback">Your feedback:</label>
<textarea id="feedback" name="feedback" cols="40"></textarea>
About 40 average character columns wide; rows defaults to 2.
How It Works
- cols="40" sets the visible width to roughly 40 character columns.
- Label + id keeps the control accessible for screen readers and clicks.
- Empty body means no default text; users start with a blank field.
- 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.
<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>
How It Works
- rows="5" shows five lines of text height.
- cols="33" sets the visible character width.
- Default content sits between the opening and closing tags.
- 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.
<label for="notes">Notes (hard wrap):</label>
<textarea
id="notes"
name="notes"
rows="4"
cols="40"
wrap="hard"></textarea>
On submit, hard wrap can add CR+LF so lines are no longer than cols.
How It Works
- wrap="hard" asks the browser to insert line breaks for submission.
- cols must be set so the browser knows the target line width.
- soft (default) does not add extra breaks — only normalizes existing ones.
- 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.
limitNot a maxlength
cols only affects visible width. Cap length with maxlength (and validate on the server).
CSSCSS width can override
Stylesheets often set width: 100%. Then cols may not match what you see. Use both intentionally.
resizeUsers can resize the box
Most browsers show a resize handle. CSS resize controls that — independent of cols.
wraphard wrap requires cols
Without cols, wrap="hard" cannot apply the intended line width for submission.
namingNot colspan
colspan spans table cells. cols sizes a textarea. Different attributes.
Compatibility
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
Supportedcols Widely supported
Bottom line: Safe to use for character-based textarea sizing. Combine with CSS when you need responsive layouts.
Remember
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.
About the author
Developer, cloud engineer, and technical writer
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