views:

226

answers:

3

Is the CSS 'width' property applicable to a <textarea>?

In practice, people say that they use it successfully, for example using a rule like this:

textarea
{
    width:100%;
}

What's confusing me is that the CSS 2.1 specification for width says,

This property specifies the content width of boxes generated by block-level and replaced elements. This property does not apply to non-replaced inline-level elements.

I thought that a textarea is an inline-level element, because e.g. markup like this ...

<p>
This is some more text:
<textarea name="mytextarea" rows="3" cols="15">Text in the text area</textarea>
And even more, more text.
</p>

... creates a single paragraph block with text to the left and right of the <textarea>, and that therefore according to the spec the width shouldn't be applicable.

+5  A: 

Textarea is an inline level element… a replaced inline element (you get a form control, not the simple content of the element).

The spec excludes non-replaced inline elements, but textarea is not one of them.

David Dorward
Thank you explaining that.
ChrisW
A: 

you should use the 'cols' property to set the width of the textarea.

http://www.w3schools.com/TAGS/tag_textarea.asp

GSto
No. You should specify the number of cols, but if you really want to set the width than CSS is much more flexible. (And avoid W3Schools, it is error prone).
David Dorward
A: 

Width is not an acceptable attribute of the textarea element. The size of a textarea can be specified by the cols and rows attributes, although it can be better controlled through the CSS height and width properties.

superUntitled