How do I add a node ID as class to the  tag? In Drupal 7, there is a class like path-node-NID (with NID replaced by the node ID of the node being viewed) added to the &lt;body&gt; tag so we can easily add CSS styles to specific nodes. This is missing in Drupal 8.

How can I add the node ID as CSS class to the &lt;body&gt; tag?
In mytheme.theme file: add the below code.
function MYTHEME_preprocess_html(&amp;$variables) {
  // Add node ID to the body class.
  $node = \Drupal::routeMatch()-&gt;getParameter('node');
  if (is_object($node)) {
    $variables['attributes']['class'][] = 'node-' . $node-&gt;id();
  }
}

This will add &quot;node-{{nid}}&quot; class in body tag.
Another Option
You can try Node Class module as well.

Node Class is a simple module that allows users to add custom CSS
classes to any node through the node/add interface.