diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 34dbdc2..142d752 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1359,23 +1359,13 @@ function template_preprocess_html(&$variables) {
     $variables['attributes']['class'][] = 'db-offline';
   }
 
-  // Add a class that tells us whether the page is viewed by an authenticated
-  // user.
-  if ($variables['logged_in']) {
-    $variables['attributes']['class'][] = 'user-logged-in';
-  }
-  // Add a class that tells us what path the page is located make it possible
-  // to theme the page depending on the current path (e.g. node, admin, user,
-  // etc.) as well as more specific data like path-frontpage.
+  // Add a variable that tells us what path the page is located make it possible
+  // to create class and theme the page depending on the current path (e.g.
+  // node, admin, user, etc.) as well as more specific data like
+  // path-frontpage.
   $path = \Drupal::request()->getPathInfo();
-
-  if (drupal_is_front_page()) {
-    $variables['attributes']['class'][] = 'path-frontpage';
-  }
-  else {
-    $segment = explode('/', $path);
-    $variables['attributes']['class'][] = 'path-' . drupal_html_class($segment[1]);
-  }
+  $variables['root_path'] = explode('/', $path)[1];
+  $variables['attributes']['class'] = $body_classes;
 
   $site_config = \Drupal::config('system.site');
   // Construct page title.
diff --git a/core/modules/system/templates/html.html.twig b/core/modules/system/templates/html.html.twig
index 5ef96cd..b62322a 100644
--- a/core/modules/system/templates/html.html.twig
+++ b/core/modules/system/templates/html.html.twig
@@ -4,6 +4,8 @@
  * Default theme implementation for the basic structure of a single Drupal page.
  *
  * Variables:
+ * - logged_in: A flag indicating if user is logged in
+ * - is_front: A flag indicating if the current page is front page
  * - css: A list of CSS files for the current page.
  * - head: Markup for the HEAD element (including meta tags, keyword tags, and
  *   so on).
@@ -26,6 +28,12 @@
  * @ingroup themeable
  */
 #}
+{%
+  set body_classes = [
+    logged_in ? 'user-logged-in',
+    is_front ? 'path-frontpage' : 'path-' ~ root_path|clean_class,
+  ]
+%}
 <!DOCTYPE html>
 <html{{ html_attributes }}>
   <head>
@@ -34,7 +42,7 @@
     {{ styles }}
     {{ scripts }}
   </head>
-  <body{{ attributes }}>
+  <body{{ attributes.addClass(body_classes) }}>
     <a href="#main-content" class="visually-hidden focusable skip-link">
       {{ 'Skip to main content'|t }}
     </a>
