Get current taxonomy in template_preprocess_html()
First, check if the route is for a taxonomy term; then, get the term ID.

if (\Drupal::routeMatch()-&gt;getRouteName() == 'entity.taxonomy_term.canonical') {
  $term_id = \Drupal::routeMatch()-&gt;getRawParameter('taxonomy_term');
}