diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_preprocess.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_preprocess.yml
new file mode 100644
index 0000000000..7f5518e077
--- /dev/null
+++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_preprocess.yml
@@ -0,0 +1,71 @@
+langcode: en
+status: true
+dependencies: {  }
+id: test_preprocess
+label: ''
+module: views
+description: ''
+tag: ''
+base_table: entity_test
+base_field: nid
+core: '8'
+display:
+  default:
+    display_options:
+      access:
+        type: none
+      cache:
+        type: tag
+      exposed_form:
+        type: basic
+      sorts:
+        id:
+          table: entity_test
+          id: id
+          field: id
+          plugin_id: standard
+          entity_type: entity_test
+          entity_field: id
+          order: desc
+      pager:
+        type: full
+        options:
+          items_per_page: 5
+      style:
+        type: default
+      row:
+        type: 'entity:entity_test'
+      css_class: 'entity-test__default'
+    display_plugin: default
+    display_title: Master
+    id: default
+    position: 0
+  display_2:
+    display_options:
+      access:
+        type: none
+      cache:
+        type: tag
+      exposed_form:
+        type: basic
+      sorts:
+        id:
+          table: entity_test
+          id: id
+          field: id
+          plugin_id: standard
+          entity_type: entity_test
+          entity_field: id
+          order: desc
+      pager:
+        type: full
+        options:
+          items_per_page: 5
+      style:
+        type: default
+      row:
+        type: 'entity:entity_test'
+      css_class: 'entity-test__default and_another-class'
+    display_plugin: default
+    display_title: Alternate
+    id: display_2
diff --git a/core/modules/views/tests/src/Kernel/ViewsPreprocessTest.php b/core/modules/views/tests/src/Kernel/ViewsPreprocessTest.php
new file mode 100644
index 0000000000..bfb3691a0b
--- /dev/null
+++ b/core/modules/views/tests/src/Kernel/ViewsPreprocessTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Drupal\Tests\views\Kernel;
+
+use Drupal\entity_test\Entity\EntityTest;
+use Drupal\views\Views;
+
+/**
+ * Tests the preprocessing functionality in views.theme.inc.
+ *
+ * @group views
+ */
+class ViewsPreprocessTest extends ViewsKernelTestBase {
+  /**
+   * {@inheritdoc}
+   */
+  public static $testViews = ['test_preprocess'];
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = ['entity_test', 'user', 'node'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp($import_test_views = TRUE) {
+    parent::setUp();
+
+    $this->installEntitySchema('entity_test');
+  }
+
+  /**
+   * Tests css classes on displays are cleaned correctly.
+   */
+  public function testCssClassCleaning() {
+    $entity = EntityTest::create();
+    $entity->save();
+    /** @var \Drupal\Core\Render\RendererInterface $renderer */
+    $renderer = \Drupal::service('renderer');
+
+    $view = Views::getview('test_preprocess');
+    $build = $view->buildRenderable();
+    $renderer->renderRoot($build);
+    $this->assertContains('class="entity-test__default', (string) $build['#markup']);
+    $view->destroy();
+
+    $view->setDisplay('display_2');
+    $build = $view->buildRenderable();
+    $renderer->renderRoot($build);
+    $this->assertContains('class="entity-test__default and_another-class', (string) $build['#markup']);
+  }
+
+}
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc
index 8dcdf672b0..a574a9329a 100644
--- a/core/modules/views/views.theme.inc
+++ b/core/modules/views/views.theme.inc
@@ -34,8 +34,10 @@ function template_preprocess_views_view(&$variables) {
 
   $css_class = $view->display_handler->getOption('css_class');
   if (!empty($css_class)) {
-    $variables['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class);
-    $variables['attributes']['class'][] = $variables['css_class'];
+    $css_classes = explode(' ', strip_tags($css_class));
+    foreach ($css_classes as $class) {
+      $variables['attributes']['class'][] = Html::cleanCssIdentifier($class);
+    }
   }
 
   // contextual_preprocess() only works on render elements, and since this theme
