diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module
index 0ee6614..6f8eb80 100644
--- a/core/modules/rdf/rdf.module
+++ b/core/modules/rdf/rdf.module
@@ -567,10 +567,6 @@ function rdf_preprocess_image(&$variables) {
  */
 function template_preprocess_rdf_metadata(&$variables) {
   foreach ($variables['metadata'] as $key => $attributes) {
-    // Add a class so that developers viewing the HTML source can see why there
-    // are empty <span> tags in the document.
-    $attributes['class'][] = 'rdf-meta';
-    $attributes['class'][] = 'hidden';
     // The XHTML+RDFa doctype allows either <span></span> or <span /> syntax to
     // be used, but for maximum browser compatibility, W3C recommends the
     // former when serving pages using the text/html media type, see
diff --git a/core/modules/rdf/templates/rdf-metadata.html.twig b/core/modules/rdf/templates/rdf-metadata.html.twig
index 81a2f3c..ec68e13 100644
--- a/core/modules/rdf/templates/rdf-metadata.html.twig
+++ b/core/modules/rdf/templates/rdf-metadata.html.twig
@@ -13,5 +13,11 @@
  */
 #}
 {% for attributes in metadata %}
-  <span{{ attributes }}></span>
+  {%
+    set classes = [
+      'rdf-meta',
+      'hidden',
+    ]
+  %}
+  <span{{ attributes.addClass(classes) }}></span>
 {% endfor %}
