Add Taxonomy ID class to the body tag (D8) I have a taxonomy vocabulary whose various parents and children need to have different styles. I would need the tid of the every taxonomy page to appear as a class in the body tag in order to make CSS selectors. 

I tried using this to work out a solution, but it appears to work only for nodes. I get a class called path-taxonomy for every taxonomy term and that's it.

I would prefer not to install any modules. Thank you
The linked example gets the path. Here better use routing. Check the name of the matched route and then get a parameter which is defined in the route. Normally you use getParameter() to get the loaded entity, in this case it's getRawParameter() for the id:

mytheme.theme:

function mytheme_preprocess_html(&amp;$variables) {
  if (\Drupal::routeMatch()-&gt;getRouteName() == 'entity.taxonomy_term.canonical') {
    $variables['term_id'] = \Drupal::routeMatch()-&gt;getRawParameter('taxonomy_term');
  }
}


html.html.twig:

{%
  set body_classes = [
    term_id ? 'term-id-' ~ term_id,
  ]
%}
&lt;body{{ attributes.addClass(body_classes) }}&gt;