How to add a single taxonomy term as a body class in Drupal 8
i found a solution which worked perfectly for me. Add this in your .theme file and replace mytheme_preprocess_html by your theme name and field_section by name of your taxonomy field.

[https://gist.github.com/awasson/d8ef8d7c1b64b2ccb8a0][1]

&lt;?php

    /**
     * Prepares variables for the html.html.twig template.
     */

    use Drupal\taxonomy\Entity\Term;
    use Drupal\Component\Utility\Html;

    function mytheme_preprocess_html(&amp;$variables) {

      if ($node = \Drupal::routeMatch()-&gt;getParameter('node')) {

        /**
         * Get the term id from the 'field_section' taxonomy field.
         * If greater than zero, load the term and acquire the name value 
         * as a css safe value.
        */
        if($node-&gt;hasField('field_section')) {
          $tid = $node-&gt;get('field_section')-&gt;target_id;
          if($tid &gt; 0) {
            $term_object = Term::load($tid);
            $variables['attributes']['class'][] = 'terms--' . Html::getClass($term_object-&gt;get('name')-&gt;value);
          }
        }

        /**
         * Get the node id from the node object.
         * If greater than zero, add the node id to body classes  
        */
        $nid = $node-&gt;get('nid')-&gt;value;
        if($nid &gt; 0) {
          $variables['attributes']['class'][] = 'page--node-' . $nid;
        }
      }

    }