I have been trying to alter the markup generated by my webform. example webform.

Example changes which I would like to do:

  • Add the class "form-horizontal" to the classes under <form class=""/>.
  • Add the class "input-xxlarge" to each input field.
  • Remove any markup generated by the webform module (e.g. form-item, webform-component, webform-component-textarea).

I've been trying to override these values with the help of Devel. Using webform-form-[nid].tpl.php, I have the following line before I make any print statements:

$form['#attributes']['class']['0'] = 'form-horizontal';

The issue is that I can not alter the form classes. Any insight that can be shared would be highly appreciated!


1 Answer 1


Have you tried theme_form_element ?

Returns HTML for a form element.

This hook is used to alter the thme of form element in Drupal.

Check theme_field as well.

How to theme form element in Drupal 7

  • 1
    theme_form_element was the key that I was missing. Using this, I was able to add new classes to a field.
    – Hectron
    May 28, 2013 at 16:53
  • how it is possible in drupal 8
    – Vinodhini
    Sep 29, 2019 at 13:05

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