Theme a contact form I'd like to theme a contact form in Drupal 8.
I'd like to put divs around form elements (using bootstrap).

I also want to put some classes on certain elements (submit button, the form itself).
You can simply theme every form how you want. I don't like the method by @rpayanm, cuz it hard to maintane and hard readable, with big forms this is not the case, just single wrapper and simple structure.

Every form trying to use theme equals their machine name. You can find this template name in $form['#theme'] just by alter, it is always (or in most times) same as form id machine name. What you need to do is register template for it. You need to implement hook_theme(). You can write it in CUSTOMMODULE.module or in THEMENAME.theme. Theme key must be the same as in $form['#theme'], so its automatically use it, otherwise you need to add new one via form alter.

/**
 * Implements hook_theme().
 */
function MODULENAME_theme($existing, $type, $theme, $path) {
  return [
    'FORM_ID_THEME' =&gt; [
      'template' =&gt; 'custom-form-template-name',
      'render element' =&gt; 'form',
    ]
  ];
}


Drupal pass $form variable with form.

Then you must create custom-form-template-name.html.twig (with your template name from hook_theme()).

The minimal template is

{{ form }}


You also can print every field from form where you want

{{ form.field_name }}


Here you can do whatever you want with markup.

You also can pass additional data to template by implementing template_preprocess_TEMPALTENAME

function template_preprocess_FORM_ID_THEME(&amp;$variables) {
  $variables['example'] = 'This is added via preprocess';
}


And then use in template

{{ example }}
&lt;div class="first-field"&gt;
  {{ form.first_field }}
&lt;/div&gt;

&lt;div class="second-field"&gt;
  {{ form.second_field }}
&lt;/div&gt;

&lt;div class="buttons"&gt;
  {{ form.submit }}
  {{ form.preview }}
&lt;/div&gt;
{#
Don't forget to add printing form special info at the end.
Without this data form will not working propertly.
#}
{{ form.form_build_id }}
{{ form.form_token }}
{{ form.form_id }}


I think this method is more fliexible, clean and powerful.

P.s. sorry for my english, hopes someone edit and fix my mistakes :)

Example of complex form using this method.