title: Drupal 8: how can I add a class in form tag
body: <p>How can I add a class in the form attribute within a custom form? Similar to  the below:</p>
  
  <p><code>&lt;form class="mu-subscription-form"&gt;&lt;/form&gt;</code></p>
  
  <p>I have created a custom module and within the <code>/src/Form/</code>, created a form named <code>CustomForm.php</code>. Below is the <code>CustomForm.php</code>:</p>
  
  <pre><code>namespace Drupal\custom\Form;
  
  use Drupal\Core\Form\FormBase;
  use Drupal\Core\Form\FormStateInterface;
  
  /**
   * Class CustomForm.
   */
  class CustomForm extends FormBase {
  
  
    /**
     * {@inheritdoc}
     */
    public function getFormId() {
      return 'custom_form';
    }
  
    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state) {
      $form['name'] = [
        '#type' =&gt; 'textfield',
        #'#title' =&gt; $this-&gt;t('name'),
        '#weight' =&gt; '0',
      ];
      $form['submit'] = [
        '#type' =&gt; 'submit',
        '#value' =&gt; $this-&gt;t('Submit'),
        '#attributes' =&gt; array('class' =&gt; array('mu-readmore-btn')),
      ];
  
      $form['#theme'] = 'custom';
  
      return $form;
    }
  
    /**
     * {@inheritdoc}
     */
    public function validateForm(array &amp;$form, FormStateInterface $form_state) {
      parent::validateForm($form, $form_state);
    }
  
    /**
     * {@inheritdoc}
     */
    public function submitForm(array &amp;$form, FormStateInterface $form_state) {
      // Display result.
      foreach ($form_state-&gt;getValues() as $key =&gt; $value) {
        drupal_set_message($key . ': ' . $value);
      }
  
    }
  
  }
  </code></pre>
  
  <p>And I have the following content for the <code>custom.module</code>:</p>
  
  <pre><code>/**
   * Implements hook_theme().
   */
  function custom_theme() {
    /*return [
      'custom' =&gt; [
        'render element' =&gt; 'children',
      ],
    ];*/
    return array(
      'form__custom_form' =&gt; array(
        'render element' =&gt; 'form',
        'template' =&gt; 'form_custom',
      ),
    );
  }
  </code></pre>
  
  <p>I have the below content for the <code>form_custom.html.twig</code> under <code>modulename/templates/</code>:</p>
  
  <pre><code>&lt;h1&gt;TEST&lt;/h1&gt;
  &lt;form{{ element }} class="mu-subscription-form"&gt;&lt;/form&gt;
  </code></pre>
  
  <p>The form is rendered however, it is not displaying the <code>&lt;h1&gt;</code> value TEST nor showing the custom class "mu-subscription-form" within the <code>&lt;form&gt;</code> tag. </p>