tags:

views:

63

answers:

5

The "cols" attribute is required in valid HTML but I don't see the benefit of using it. Do you?

+1  A: 

It determines how wide to render the element.

David Dorward
Yes, but you can do the same through CSS and do it much more precisely.
Emanuil
The spec predates common CSS support and use (and given a monospace font (the default), columns is usually a much easier way to get the precise width you want)
David Dorward
+2  A: 

If the client does not support CSS, it will still be able to see <textarea> with right width.

fuwaneko
Are there clients that do not CSS and if the <textarea> requires a "cols" attribute, why the <input type="text"> does not?
Emanuil
Because it has other attributes: `<input type="text" size="10" maxlength="20">` See also: http://www.w3.org/TR/html4/interact/forms.html#h-17.4
Denilson Sá
@Denilson — but they aren't mandatory.
David Dorward
Because it only makes sense for `text` and `password` types, and the `<input>` element is also used for `radio`, `checkbox`, `button`... Also remember the spec was made to officialize the behavior already common among existing browsers. It doesn't need to make perfect sense.
Denilson Sá
@Emanuil. Lynx does not support CSS for example. The HTML specification does not give any answers on your quiestion. It just says, "cols and rows are required". I think they are required as fallback if browser doesn't support CSS, or if user disabled it; it's reasonable. Also CSS width/height and cols/rows act differently.
fuwaneko
A: 

"cols" using for increase the width of textarea` in html.

A: 

When browsers and html parsing software looks at HTML it will be looking for a set of mandatory attributes on a tag. Such as every <img> tag needs an alt="" attribute.

So when running your site through a HTML validator you need to make sure the mandatory attributes are in place else validation will fail..

Secondly when a user is using assistive technologies, they tend to turn off CSS/Javascript altogether so making sure you have cols="" in there is important. Screan readers and such may not be able to parse your webpage properly if it can't find required attributes for your markup.

Conclusion: Theres a bigger picture than just tweaking some stylesheet info. Make sure you conform to spec. If you want to style things pretty make sure you have sensible fallback for non-css webpages.

Paul Dragoonis