diff --git a/core/modules/locale/src/Tests/LocaleContentTest.php b/core/modules/locale/src/Tests/LocaleContentTest.php
index 3ec3c71..5229eb7 100644
--- a/core/modules/locale/src/Tests/LocaleContentTest.php
+++ b/core/modules/locale/src/Tests/LocaleContentTest.php
@@ -177,26 +177,26 @@ public function testContentTypeDirLang() {
 
     // Check if English node does not have lang tag.
     $this->drupalGet('node/' . $nodes['en']->id());
-    $pattern = '|class="[^"]*node[^"]*"[^<>]*lang="en"|';
-    $this->assertNoPattern($pattern, 'The lang tag has not been assigned to the English node.');
+    $element = $this->xpath('//article[@class and contains(concat(" ", normalize-space(@class), " "), " node ") and @lang="en"]');
+    $this->assertTrue(empty($element), 'The lang tag has not been assigned to the English node.');
 
     // Check if English node does not have dir tag.
-    $pattern = '|class="[^"]*node[^"]*"[^<>]*dir="ltr"|';
-    $this->assertNoPattern($pattern, 'The dir tag has not been assigned to the English node.');
+    $element = $this->xpath('//article[@class and contains(concat(" ", normalize-space(@class), " "), " node ") and @dir="ltr"]');
+    $this->assertTrue(empty($element), 'The dir tag has not been assigned to the English node.');
 
     // Check if Arabic node has lang="ar" & dir="rtl" tags.
     $this->drupalGet('node/' . $nodes['ar']->id());
-    $pattern = '|class="[^"]*node[^"]*"[^<>]*lang="ar" dir="rtl"|';
-    $this->assertPattern($pattern, 'The lang and dir tags have been assigned correctly to the Arabic node.');
+    $element = $this->xpath('//article[@class and contains(concat(" ", normalize-space(@class), " "), " node ") and @lang="ar" and @dir="rtl"]');
+    $this->assertTrue(!empty($element), 'The lang and dir tags have been assigned correctly to the Arabic node.');
 
     // Check if Spanish node has lang="es" tag.
     $this->drupalGet('node/' . $nodes['es']->id());
-    $pattern = '|class="[^"]*node[^"]*"[^<>]*lang="es"|';
-    $this->assertPattern($pattern, 'The lang tag has been assigned correctly to the Spanish node.');
+    $element = $this->xpath('//article[@class and contains(concat(" ", normalize-space(@class), " "), " node ") and @lang="es"]');
+    $this->assertTrue(!empty($element), 'The lang tag has been assigned correctly to the Spanish node.');
 
     // Check if Spanish node does not have dir="ltr" tag.
-    $pattern = '|class="[^"]*node[^"]*"[^<>]*lang="es" dir="ltr"|';
-    $this->assertNoPattern($pattern, 'The dir tag has not been assigned to the Spanish node.');
+    $element = $this->xpath('//article[@class and contains(concat(" ", normalize-space(@class), " "), " node ") and @lang="es" and @dir="ltr"]');
+    $this->assertTrue(empty($element), 'The dir tag has not been assigned to the Spanish node.');
   }
 
 }
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index fefd6d5..f782246 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -653,25 +653,6 @@ function template_preprocess_node(&$variables) {
 
   // Add article ARIA role.
   $variables['attributes']['role'] = 'article';
-
-  // Gather node classes.
-  $variables['attributes']['class'][] = 'node';
-  $variables['attributes']['class'][] = drupal_html_class('node--type-' . $node->bundle());
-  if ($node->isPromoted()) {
-    $variables['attributes']['class'][] = 'node--promoted';
-  }
-  if ($node->isSticky()) {
-    $variables['attributes']['class'][] = 'node--sticky';
-  }
-  if (!$node->isPublished()) {
-    $variables['attributes']['class'][] = 'node--unpublished';
-  }
-  if ($variables['view_mode']) {
-    $variables['attributes']['class'][] = drupal_html_class('node--view-mode-' . $variables['view_mode']);
-  }
-  if (isset($variables['preview'])) {
-    $variables['attributes']['class'][] = 'node--preview';
-  }
 }
 
 /**
diff --git a/core/modules/node/templates/node.html.twig b/core/modules/node/templates/node.html.twig
index c80eecb..ddbb63d 100644
--- a/core/modules/node/templates/node.html.twig
+++ b/core/modules/node/templates/node.html.twig
@@ -77,7 +77,20 @@
  * @ingroup themeable
  */
 #}
-<article{{ attributes }}>
+
+{%
+  set classes = [
+    'node',
+    'node--type-' ~ node.bundle|clean_class,
+    node.promoted ? 'node--promoted',
+    node.sticky ? 'node--sticky',
+    not node.published ? 'node--unpublished',
+    'node--view-mode-' ~ view_mode|clean_class,
+    preview ? ' node--preview'
+  ]
+%}
+
+<article{{ attributes.addClass(classes) }}>
 
   {{ title_prefix }}
   {% if not page %}
diff --git a/core/themes/bartik/templates/node.html.twig b/core/themes/bartik/templates/node.html.twig
index d45b0f0..186f3e6 100644
--- a/core/themes/bartik/templates/node.html.twig
+++ b/core/themes/bartik/templates/node.html.twig
@@ -71,7 +71,20 @@
  * @see template_preprocess_node()
  */
 #}
-<article class="{{ attributes.class }} clearfix"{{ attributes|without('class') }}>
+{%
+  set classes = [
+    'node',
+    'node--type-' ~ node.bundle|clean_class,
+    node.promoted ? 'node--promoted',
+    node.sticky ? 'node--sticky',
+    not node.published ? 'node--unpublished',
+    'node--view-mode-' ~ view_mode|clean_class,
+    preview ? ' node--preview',
+    'clearfix'
+  ]
+%}
+
+<article{{ attributes.addClass(classes) }}>
 
   <header>
     {{ title_prefix }}
