How to determine if the current Drupal page is a contact page? With Drupal 8, in THEMENAME.theme I can generate a class based on the current node ID which will be inserted in the body tag :

In the THEMENAME_preprocess_html() function, i use :

$node = \Drupal::routeMatch()-&gt;getParameter('node');
  if($node) {
    $variables['attributes']['class'][] = 'node-' . $node-&gt;id();
  }


But how can i determine if we are on the contact page since it is not a node ?
Have you tried

\Drupal::routeMatch()-&gt;getParameter('contact_form');


This returns an object of type ContactForm when the user is on a contact page. A simple detection you can do with getRouteName():

if ('entity.contact_form.canonical' === \Drupal::routeMatch()-&gt;getRouteName()) {
  // huhu, a contact form
}


You can have a look at ./core/modules/contact/contact.routing.yml. There are all routes available.