diff --git a/core/modules/views/src/Plugin/views/style/StylePluginBase.php b/core/modules/views/src/Plugin/views/style/StylePluginBase.php
index 1831fdb672bce771ca022f566515dd3156ad325d..e11dbb89c48da7e3d1ae1c328d9ede23690711b0 100644
--- a/core/modules/views/src/Plugin/views/style/StylePluginBase.php
+++ b/core/modules/views/src/Plugin/views/style/StylePluginBase.php
@@ -5,6 +5,7 @@
 use Drupal\Component\Utility\Html;
 use Drupal\Component\Utility\Xss;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Render\Markup;
 use Drupal\views\Plugin\views\display\DisplayPluginBase;
 use Drupal\views\Plugin\views\PluginBase;
 use Drupal\views\Plugin\views\wizard\WizardInterface;
@@ -575,13 +576,13 @@ public function renderGrouping($records, $groupings = [], $group_rendered = NULL
           // we can control any special formatting of the grouping field through
           // the admin or theme layer or anywhere else we'd like.
           if (isset($this->view->field[$field])) {
-            $group_content = $this->getField($index, $field);
+            $group_content = (string) $this->getField($index, $field);
             if ($this->view->field[$field]->options['label']) {
               $delimiter = $this->view->field[$field]->options['element_label_colon'] ? ': ' : ' ';
               $group_content = $this->view->field[$field]->options['label'] . $delimiter . $group_content;
             }
             if ($rendered) {
-              $grouping = (string) $group_content;
+              $grouping = $group_content;
               if ($rendered_strip) {
                 $group_content = $grouping = strip_tags(htmlspecialchars_decode($group_content));
               }
@@ -598,7 +599,7 @@ public function renderGrouping($records, $groupings = [], $group_rendered = NULL
 
           // Create the group if it does not exist yet.
           if (empty($set[$grouping])) {
-            $set[$grouping]['group'] = $group_content;
+            $set[$grouping]['group'] = Markup::create($group_content);
             $set[$grouping]['level'] = $level;
             $set[$grouping]['rows'] = [];
           }