According to the Form API, you control the number of columns in a textarea with the #cols attribute. However, setting this seems to have no effect when I use it inside a $form array (the companion #rows attribute works as expected).

This is question is already on stack overflow however the answer utilizes css instead of the cols attribute which seems like a cheat.

    $form['message'] = array(
        '#type' => 'textarea',
        '#title' => t('Message'),
        '#resizable' => FALSE,
        '#cols' => 20, 
        '#rows' => 10,

Drupal will add the cols attribute to the textarea, however its CSS which controls it. i.e Width of the textarea or its container is controlling it.

Here is the fiddle example explaining this scenario

In the above example first textarea didn't affected by any CSS so it has 100 cols, however the second one is bounded with another container and its width is restricted, so textarea is rendered within the available width that's why cols value didnt affected the textarea.

The same is applicable for rows attribute when you set height attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.