diff --git a/core/includes/menu.inc b/core/includes/menu.inc
index 681bdbbd8f50b255c4d036df9217bd9fa31faff7..d57849904c98ff72f4f96f6a78d91ec11951d68e 100644
--- a/core/includes/menu.inc
+++ b/core/includes/menu.inc
@@ -34,7 +34,7 @@ function template_preprocess_menu_local_task(&$variables) {
   $link_text = $link['title'];
 
   if (!empty($variables['element']['#active'])) {
-    $variables['attributes']['class'] = array('is-active');
+    $variables['is_active'] = TRUE;
 
     // Add text to indicate active tab for non-visual users.
     $active = SafeMarkup::format('<span class="visually-hidden">@label</span>', array('@label' => t('(active tab)')));
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 2aef832c819c0665f6207638d5a65d42ae7a77d4..62bbb58e4a93121b63b77c6831cea818bc95238c 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1246,11 +1246,8 @@ function template_preprocess_html(&$variables) {
   $variables['html_attributes']['lang'] = $language_interface->getId();
   $variables['html_attributes']['dir'] = $language_interface->getDirection();
 
-  // Compile a list of classes that are going to be applied to the body element.
-  // This allows advanced theming based on context (home page, node of certain
-  // type, etc.).
   if (isset($variables['db_is_active']) && !$variables['db_is_active']) {
-    $variables['attributes']['class'][] = 'db-offline';
+    $variables['db_offline'] = TRUE;
   }
 
   // Add a variable for the root path. This can be used to create a class and
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 9220fe7ef11e2a60e00c2bb986f213b3a82e20bc..ee12a41fe2d46942b69c0c24a1e3cb884322717e 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -1192,7 +1192,6 @@ function template_preprocess_file_managed_file(&$variables) {
   if (!empty($element['#attributes']['class'])) {
     $variables['attributes']['class'] = (array) $element['#attributes']['class'];
   }
-  $variables['attributes']['class'][] = 'form-managed-file';
 }
 
 /**
diff --git a/core/modules/file/templates/file-managed-file.html.twig b/core/modules/file/templates/file-managed-file.html.twig
index 9a33ae1f10775582dc721a69b5eb6ecc391a25cd..7a875118c394648a637dc616cd89d3959e2bfe9b 100644
--- a/core/modules/file/templates/file-managed-file.html.twig
+++ b/core/modules/file/templates/file-managed-file.html.twig
@@ -12,6 +12,6 @@
  * @ingroup themeable
  */
 #}
-<div{{ attributes }}>
+<div{{ attributes.addClass('form-managed-file') }}>
   {{ element }}
 </div>
diff --git a/core/modules/system/templates/html.html.twig b/core/modules/system/templates/html.html.twig
index a11c8a47798a8a6456cd005625a4b703083434b3..94785426e5970be13babd4cff09e2a01e8018cc3 100644
--- a/core/modules/system/templates/html.html.twig
+++ b/core/modules/system/templates/html.html.twig
@@ -23,6 +23,7 @@
  * - styles: Style tags necessary to import all necessary CSS files in the head.
  * - scripts: Script tags necessary to load the JavaScript files and settings
  *   in the head.
+ * - db_offline: A flag indicating if the database is offline.
  *
  * @see template_preprocess_html()
  *
diff --git a/core/modules/system/templates/menu-local-task.html.twig b/core/modules/system/templates/menu-local-task.html.twig
index 5939203c5221b91affe09447d63152fa40687862..ec02a8d530c4bb1a2e1061b258916a185bde63d8 100644
--- a/core/modules/system/templates/menu-local-task.html.twig
+++ b/core/modules/system/templates/menu-local-task.html.twig
@@ -5,6 +5,7 @@
  *
  * Available variables:
  * - attributes: HTML attributes for the wrapper element.
+ * - is_active: Whether the task item is an active tab.
  * - link: A rendered link element.
  *
  * Note: This template renders the content for each task item in
diff --git a/core/themes/classy/templates/content-edit/file-managed-file.html.twig b/core/themes/classy/templates/content-edit/file-managed-file.html.twig
index d7b91202097217a9541100ac43d0ba8fd912bc97..43739bedc03da23e022a1c2dd41918b658161517 100644
--- a/core/themes/classy/templates/content-edit/file-managed-file.html.twig
+++ b/core/themes/classy/templates/content-edit/file-managed-file.html.twig
@@ -10,6 +10,6 @@
  * @see template_preprocess_file_managed_file()
  */
 #}
-<div{{ attributes }}>
+<div{{ attributes.addClass('form-managed-file') }}>
   {{ element }}
 </div>
diff --git a/core/themes/classy/templates/layout/html.html.twig b/core/themes/classy/templates/layout/html.html.twig
index 1bb0ac6ab0d218bdd018fc7dd5e50c135bbfabd7..b01961833471a1a94675c96b00f06a46c6ab9ae2 100644
--- a/core/themes/classy/templates/layout/html.html.twig
+++ b/core/themes/classy/templates/layout/html.html.twig
@@ -23,6 +23,7 @@
  * - styles: Style tags necessary to import all necessary CSS files in the head.
  * - scripts: Script tags necessary to load the JavaScript files and settings
  *   in the head.
+ * - db_offline: A flag indicating if the database is offline.
  *
  * @see template_preprocess_html()
  */
@@ -32,6 +33,7 @@
     logged_in ? 'user-logged-in',
     not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class,
     node_type ? 'node--type-' ~ node_type|clean_class,
+    db_offline ? 'db-offline',
   ]
 %}
 <!DOCTYPE html>
diff --git a/core/themes/classy/templates/navigation/menu-local-task.html.twig b/core/themes/classy/templates/navigation/menu-local-task.html.twig
index 602ba62b0dae3206a9e231a7e95d154878e27c4c..b8559815b9e937120f8fd4f87bcfe27e7a30c0b0 100644
--- a/core/themes/classy/templates/navigation/menu-local-task.html.twig
+++ b/core/themes/classy/templates/navigation/menu-local-task.html.twig
@@ -5,6 +5,7 @@
  *
  * Available variables:
  * - attributes: HTML attributes for the wrapper element.
+ * - is_active: Whether the task item is an active tab.
  * - link: A rendered link element.
  *
  * Note: This template renders the content for each task item in
@@ -13,4 +14,4 @@
  * @see template_preprocess_menu_local_task()
  */
 #}
-<li{{ attributes }}>{{ link }}</li>
+<li{{ attributes.addClass(is_active ? 'is-active') }}>{{ link }}</li>