title: Symfony2 - FormBuilder - add a class to the field and input
body: <p>I want to add a class to certain input or label elements in a <a href="https://symfony.com" rel="nofollow noreferrer">Symfony</a> application.</p>
  
  <p>I can do something like this in a form on the Twig level:</p>
  
  <pre><code>&lt;div class="row"&gt;
      {{ form_label(form.subject) }}
      {{ form_widget(form.subject, { 'attr': {'class': 'c4'} }) }}
  &lt;/div&gt;
  </code></pre>
  
  <p>This works fine. But I have to setup and write out the whole template for every form manually. And I actually want to use:</p>
  
  <pre><code>{{ form_widget(form) }}
  </code></pre>
  
  <p>So, I was thinking, how could I add a CSS class for a label or an input somewhere in the <code>FormType</code>:</p>
  
  <pre><code>class SystemNotificationType extends AbstractType {
      public function buildForm(FormBuilder $builder, array $options) {
          $builder-&gt;add('subject', 'text', array(
              'label' =&gt; 'Subject'
          ));
  </code></pre>
  
  <p>I think this might be more useful, as you can configure the whole form in one place.</p>
  
  <p><em>How can this be done?</em> Maybe I'm thinking about it the wrong way.</p>