diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index e772289..a00f64a 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -426,15 +426,13 @@ function _theme($hook, $variables = array()) {
     if (!isset($default_attributes)) {
       $default_attributes = new Attribute();
     }
-    foreach (array('attributes', 'title_attributes', 'content_attributes') as $key) {
-      if (isset($variables[$key]) && !($variables[$key] instanceof Attribute)) {
-        if ($variables[$key]) {
-          $variables[$key] = new Attribute($variables[$key]);
-        }
-        else {
-          // Create empty attributes.
-          $variables[$key] = clone $default_attributes;
-        }
+    if (isset($variables['attributes']) && !($variables['attributes'] instanceof Attribute)) {
+      if ($variables['attributes']) {
+        $variables['attributes'] = new Attribute($variables['attributes']);
+      }
+      else {
+        // Create empty attributes.
+        $variables['attributes'] = clone $default_attributes;
       }
     }
 
@@ -1601,8 +1599,6 @@ function _template_preprocess_default_variables() {
   // Variables that don't depend on a database connection.
   $variables = array(
     'attributes' => array(),
-    'title_attributes' => array(),
-    'content_attributes' => array(),
     'title_prefix' => array(),
     'title_suffix' => array(),
     'db_is_active' => !defined('MAINTENANCE_MODE'),
@@ -2004,27 +2000,19 @@ function template_preprocess_field(&$variables, $hook) {
     $default_attributes = new Attribute;
   }
 
-  // We want other preprocess functions and the theme implementation to have
-  // fast access to the field item render arrays. The item render array keys
-  // (deltas) should always be numerically indexed starting from 0, and looping
-  // on those keys is faster than calling element_children() or looping on all
-  // keys within $element, since that requires traversal of all element
-  // properties.
-  $variables['items'] = array();
-  $delta = 0;
-  while (!empty($element[$delta])) {
-    $variables['items'][$delta]['content'] = $element[$delta];
-
-    // Modules (e.g., rdf.module) can add field item attributes (to
-    // $item->_attributes) within hook_entity_prepare_view(). Some field
-    // formatters move those attributes into some nested formatter-specific
-    // element in order have them rendered on the desired HTML element (e.g., on
-    // the <a> element of a field item being rendered as a link). Other field
-    // formatters leave them within $element['#items'][$delta]['_attributes'] to
-    // be rendered on the item wrappers provided by field.html.twig.
-    $variables['items'][$delta]['attributes'] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes);
-    $delta++;
+  // Modules (e.g., rdf.module) can add field item attributes (to
+  // $item->_attributes) within hook_entity_prepare_view(). Some field
+  // formatters move those attributes into some nested formatter-specific
+  // element in order have them rendered on the desired HTML element (e.g., on
+  // the <a> element of a field item being rendered as a link). Other field
+  // formatters leave them within $element['#items'][$delta]['_attributes'] to
+  // be rendered on the item wrappers provided by field.html.twig.
+  foreach ($variables['items'] as $delta => $item) {
+    $variables['item_attributes'][$delta] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone $default_attributes;
   }
+
+  $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : clone $default_attributes;
+  $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : clone $default_attributes;
 }
 
 /**
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index 83f4a40..cdd0c53 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -11,6 +11,7 @@
 use Drupal\language\ConfigurableLanguageInterface;
 use Drupal\system\Entity\Menu;
 use Drupal\block\Entity\Block;
+use Drupal\Core\Template\Attribute;
 
 /**
  * Implements hook_help().
@@ -279,6 +280,10 @@ function template_preprocess_block(&$variables) {
     $variables['attributes']['aria-describedby'] = $variables['title_attributes']['id'];
   }
 
+  $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute();
+
+  // Add default class for block content.
+  $variables['content_attributes'] = new Attribute($variables['content_attributes']);
 }
 
 /**
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index bdf53bf..a6bd67b 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -24,6 +24,7 @@
 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
 use Drupal\Core\Field\FieldDefinitionInterface;
 use Drupal\Core\Render\Element;
+use Drupal\Core\Template\Attribute;
 use Drupal\Core\Url;
 use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\field\FieldConfigInterface;
@@ -812,6 +813,8 @@ function template_preprocess_comment(&$variables) {
   $variables['attributes']['data-comment-user-id'] = $comment->getOwnerId();
 
   $variables['content_attributes']['class'][] = 'content';
+  $variables['content_attributes'] = new Attribute($variables['content_attributes']);
+  $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute();
 }
 
 /**
@@ -836,7 +839,6 @@ function comment_preprocess_field(&$variables) {
 
     // Adjust a comment field's attributes.
     $variables['attributes']['class'][] = 'comment-wrapper';
-    $variables['title_attributes']['class'][] = 'title';
 
     // Append additional attributes (eg. RDFa) from the first field item.
     $variables['attributes'] += $variables['items'][0]['attributes']->storage();
@@ -844,7 +846,8 @@ function comment_preprocess_field(&$variables) {
     // Create separate variables for the comments and comment form.
     $variables['comments'] = $element[0]['comments'];
     $variables['comment_form'] = $element[0]['comment_form'];
-    $variables['content_attributes']['class'] = array('title', 'comment-form__title');
+    $variables['title_attributes']->addClass('title');
+    $variables['content_attributes']->addClass(array('title', 'comment-form__title'));
   }
 }
 
diff --git a/core/modules/search/search.module b/core/modules/search/search.module
index 91afbc1..8cbd2d1 100644
--- a/core/modules/search/search.module
+++ b/core/modules/search/search.module
@@ -114,7 +114,7 @@ function search_theme() {
 function search_preprocess_block(&$variables) {
   if ($variables['plugin_id'] == 'search_form_block') {
     $variables['attributes']['role'] = 'search';
-    $variables['attributes']['class'][] = 'container-inline';
+    $variables['attributes']->addClass('container-inline');
   }
 }
 
diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc
index 4c84c84..2c45678 100644
--- a/core/modules/search/search.pages.inc
+++ b/core/modules/search/search.pages.inc
@@ -7,6 +7,7 @@
 
 use Drupal\Component\Utility\String;
 use Drupal\Core\Language\LanguageInterface;
+use Drupal\Core\Template\Attribute;
 
 /**
  * Implements hook_theme_suggestions_HOOK().
@@ -60,5 +61,7 @@ function template_preprocess_search_result(&$variables) {
   // Provide separated and grouped meta information..
   $variables['info_split'] = $info;
   $variables['info'] = implode(' - ', $info);
+  $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute();
+  $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : new Attribute();
 }
 
diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme
index 60f9a34..da3caa9 100644
--- a/core/themes/bartik/bartik.theme
+++ b/core/themes/bartik/bartik.theme
@@ -135,9 +135,9 @@ function bartik_preprocess_menu(&$variables) {
 function bartik_preprocess_field(&$variables) {
   $element = $variables['element'];
   if ($element['#field_type'] == 'taxonomy_term_reference') {
-    $variables['title_attributes']['class'][] = 'field-label';
+    $variables['title_attributes']->addClass('field-label');
     if ($variables['element']['#label_display'] == 'inline') {
-      $variables['title_attributes']['class'][] = 'inline';
+      $variables['title_attributes']->addClass('inline');
     }
   }
 }
diff --git a/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig b/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig
index a8e94e2..8051999 100644
--- a/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig
+++ b/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig
@@ -22,8 +22,8 @@
     <h3{{ title_attributes }}>{{ label }}</h3>
   {% endif %}
   <ul{{ content_attributes.addClass('links', 'field-items') }}>
-    {% for item in items %}
-      <li{{ item.attributes }}>{{ item.content }}</li>
+    {% for delta, item in items %}
+      <li{{ item_attributes[delta].addClass('taxonomy-term-reference-' ~ delta) }}>{{ item }}</li>
     {% endfor %}
   </ul>
 </div>
