5

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.

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

-1

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

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

1 Comment

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.