diff --git a/core/modules/comment/templates/comment.html.twig b/core/modules/comment/templates/comment.html.twig
index 24dbd079627bb40f256b4162249d6f33da9d156f..ba62e2ba254a44e6f3618a70f0f2b65d433866a7 100644
--- a/core/modules/comment/templates/comment.html.twig
+++ b/core/modules/comment/templates/comment.html.twig
@@ -70,7 +70,7 @@
   set classes = [
     'comment',
     status != 'published' ? status,
-    not author_id ? 'by-anonymous',
+    comment.owner.anonymous ? 'by-anonymous',
     author_id and author_id == commented_entity.getOwnerId() ? 'by-' ~ commented_entity.getEntityTypeId() ~ '-author',
     'clearfix',
   ]
diff --git a/core/themes/bartik/templates/comment.html.twig b/core/themes/bartik/templates/comment.html.twig
index 0fa199146bdae715590d1774d9415dc513b99158..0e402303f998df958c3fafacd6790882c311055a 100644
--- a/core/themes/bartik/templates/comment.html.twig
+++ b/core/themes/bartik/templates/comment.html.twig
@@ -68,7 +68,7 @@
   set classes = [
     'comment',
     status != 'published' ? status,
-    not author_id ? 'by-anonymous',
+    comment.owner.anonymous ? 'by-anonymous',
     author_id and author_id == commented_entity.getOwnerId() ? 'by-' ~ commented_entity.getEntityTypeId() ~ '-author',
     'clearfix',
   ]