ChrisW
ChrisW

Reputation: 56113

Is 'width' applicable to a textarea?

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.

Upvotes: 5

Views: 1021

Answers (3)

superUntitled
superUntitled

Reputation: 22527

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.

Upvotes: 0

GSto
GSto

Reputation: 42350

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

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

Upvotes: -1

Quentin
Quentin

Reputation: 943564

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.

Upvotes: 6

Related Questions