<textarea cols="">
Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
- Attribute of
- HTML5 Textarea Attributes: Here's What You Should Know
- What does
<textarea cols="">
do? - Specifies the visible width of a <textarea> element in average character widths. Defaults to 20 if not specified.
Code Example
<textarea cols="40" placeholder="Approximately 40 characters will fit on a line" style="width:auto; font-family:monospace;"></textarea>
Controlling the Width of a textarea
There are two ways of controlling the width of a textarea
:
- The
cols
attribute. - The
width
CSS property.
The cols
attribute is used to tell the browser how many average-width characters should fit on a single line. The width
attribute simply controls how the browser visually presents the textarea
. It’s important to note that the width
attribute will overrule the cols
attribute–even if the cols
attribute is specified after the width
property. For example, the follow code will produce a textarea that is 100 pixels wide regardless of the cols
attribute applied to the textarea
.
<style> .example { width: 300px; } </style> <textarea class="example" cols="20"></textarea>
When rendered by the browser, the cols="20"
attribute is effectively ignored by the browser.
.example{width: 300px;}