Adding a class to a region I am working on my theme in Drupal 8 and I want to add a class to my header div. I tried adding this to the region.vars.php file. 

if ($region === 'header') {
  $variables[header]['class'][] = 'navbar-right';
}


It's not working, though. This is the complete region.vars.php file. 

&lt;?php
/**
 * @file
 * region.vars.php
 */

use Drupal\Core\Template\Attribute;

/**
 * Implements hook_preprocess_region().
 */
function bootstrap_preprocess_region(&amp;$variables) {
  $region = $variables['elements']['#region'];
  $variables['region'] = $region;
  $variables['content'] = $variables['elements']['#children'];

  $theme = \Drupal::theme()-&gt;getActiveTheme()-&gt;getName();


  // Content region.
  if ($region === 'content') {
    // @todo is this actually used properly?
    $variables['theme_hook_suggestions'][] = 'region__no_wrapper';
  }
  // Help region.
  elseif ($region === 'help' &amp;&amp; !empty($variables['content'])) {
    $content = $variables['content'];
    $variables['content'] = array(
      'icon' =&gt; array(
        '#markup' =&gt; _bootstrap_icon('question-sign'),
      ),
      'content' =&gt; array(
        '#markup' =&gt; $content,
      ),
    );
    $variables['attributes']['class'][] = 'alert';
    $variables['attributes']['class'][] = 'alert-info';
    $variables['attributes']['class'][] = 'messages';
    $variables['attributes']['class'][] = 'info';
  }

  // Support for "well" classes in regions.
  static $wells;
  if (!isset($wells)) {
    foreach (system_region_list($theme) as $name =&gt; $title) {
      $wells[$name] = bootstrap_setting('region_well-' . $name);
    }
  }
  if (!empty($wells[$region])) {
    $variables['attributes']['class'][] = $wells[$region];
  }

   if ($region === 'header') {
    $variables[header]['class'][] = 'navbar-right';
  }

}


I got most of this code from the Drupal 8 bootstrap theme. Everything else is working.
What I normally do for all my themes is to add the missing region region-name class to each region by implementing hook_preproccess_HOOK in MYTHEME.theme.

/**
 * Implements template_preprocess_region().
 */
function MYTHEME_preprocess_region(&amp;$variables) {

  // Add missing region CSS classes.
  $variables['attributes']['class'][] = 'region';

  if (isset($variables['region']) &amp;&amp; !empty($variables['region'])) {

    $variables['attributes']['class'][] = 'region-' . str_replace('_', '-', $variables['region']);
  }
}