How can I add a CSS class to the body tag based on the current path alias?
In your theme, you can add the following code in template_preprocess_html:
$current_path = \Drupal::service('path.current')-&gt;getPath();
$path_alias = \Drupal::service('path_alias.manager')-&gt;getAliasByPath($current_path);
$path_alias = ltrim($path_alias, '/');
$variables['attributes']['class'][] = \Drupal\Component\Utility\Html::cleanCssIdentifier($path_alias);