diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/MediaOverviewTest.php b/core/modules/media_library/tests/src/FunctionalJavascript/MediaOverviewTest.php
index bc038b53e2..5e7c7c47f6 100644
--- a/core/modules/media_library/tests/src/FunctionalJavascript/MediaOverviewTest.php
+++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaOverviewTest.php
@@ -96,7 +96,7 @@ public function testAdministrationPage() {
 
     // Test that selecting elements as a part of bulk operations works.
     $page->selectFieldOption('Media type', '- Any -');
-    $assert_session->elementExists('css', '#views-exposed-form-media-library-page')->submit();
+    $assert_session->elementExists('css', '.views-exposed-form-media-library-page')->submit();
     $this->waitForText('Dog');
 
     // This tests that anchor tags clicked inside the preview are suppressed.
diff --git a/core/modules/views/js/ajax_view.es6.js b/core/modules/views/js/ajax_view.es6.js
index 55c85fda18..6c72470fa1 100644
--- a/core/modules/views/js/ajax_view.es6.js
+++ b/core/modules/views/js/ajax_view.es6.js
@@ -99,12 +99,7 @@
     this.settings = settings;
 
     // Add the ajax to exposed forms.
-    this.$exposed_form = $(
-      `form#views-exposed-form-${settings.view_name.replace(
-        /_/g,
-        '-',
-      )}-${settings.view_display_id.replace(/_/g, '-')}`,
-    );
+    this.$exposed_form = $('form#' + settings.view_html_id);
     this.$exposed_form
       .once('exposed-form')
       .each($.proxy(this.attachExposedFormAjax, this));
diff --git a/core/modules/views/js/ajax_view.js b/core/modules/views/js/ajax_view.js
index 95a803d7fe..531a2d9406 100644
--- a/core/modules/views/js/ajax_view.js
+++ b/core/modules/views/js/ajax_view.js
@@ -65,7 +65,7 @@
 
     this.settings = settings;
 
-    this.$exposed_form = $('form#views-exposed-form-' + settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-'));
+    this.$exposed_form = $('form#' + settings.view_html_id);
     this.$exposed_form.once('exposed-form').each($.proxy(this.attachExposedFormAjax, this));
 
     this.$view.filter($.proxy(this.filterNestedViews, this)).once('ajax-pager').each($.proxy(this.attachPagerAjax, this));
@@ -126,4 +126,4 @@
       $(scrollTarget).animate({ scrollTop: offset.top - 10 }, 500);
     }
   };
-})(jQuery, Drupal, drupalSettings);
\ No newline at end of file
+})(jQuery, Drupal, drupalSettings);
diff --git a/core/modules/views/src/Controller/ViewAjaxController.php b/core/modules/views/src/Controller/ViewAjaxController.php
index 8b7d115fa5..99c03635bb 100644
--- a/core/modules/views/src/Controller/ViewAjaxController.php
+++ b/core/modules/views/src/Controller/ViewAjaxController.php
@@ -143,6 +143,7 @@ public function ajaxView(Request $request) {
           'view_dom_id',
           'pager_element',
           'view_base_path',
+          'view_html_id',
           AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER,
           FormBuilderInterface::AJAX_FORM_REQUEST,
           MainContentViewSubscriber::WRAPPER_FORMAT,
diff --git a/core/modules/views/src/Form/ViewsExposedForm.php b/core/modules/views/src/Form/ViewsExposedForm.php
index 7e92378ae3..b4fd06b9ae 100644
--- a/core/modules/views/src/Form/ViewsExposedForm.php
+++ b/core/modules/views/src/Form/ViewsExposedForm.php
@@ -148,7 +148,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
 
     $form['#action'] = $form_action;
     $form['#theme'] = $view->buildThemeFunctions('views_exposed_form');
-    $form['#id'] = Html::cleanCssIdentifier('views_exposed_form-' . $view->storage->id() . '-' . $display['id']);
+    $clean_form_id = Html::cleanCssIdentifier('views_exposed_form-' . $view->storage->id() . '-' . $display['id']);
+    $form['#attributes']['class'][] = $clean_form_id;
+    // The form can be possibly rendered twice on a page, make the id unique.
+    $form['#id'] = Html::getUniqueId($clean_form_id);
 
     /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form_plugin */
     $exposed_form_plugin = $view->display_handler->getPlugin('exposed_form');
diff --git a/core/modules/views/tests/src/Kernel/ViewElementTest.php b/core/modules/views/tests/src/Kernel/ViewElementTest.php
index 921fac70b1..8c478938ff 100644
--- a/core/modules/views/tests/src/Kernel/ViewElementTest.php
+++ b/core/modules/views/tests/src/Kernel/ViewElementTest.php
@@ -126,7 +126,7 @@ public function testViewElementEmbed() {
     $this->setRawContent($renderer->renderRoot($render));
 
     // Ensure that the exposed form is rendered.
-    $this->assertEqual(1, count($this->xpath('//form[@class="views-exposed-form"]')));
+    $this->assertEqual(1, count($this->xpath('//form[@class="views-exposed-form views-exposed-form-test-view-embed-embed-2"]')));
   }
 
 }
diff --git a/core/modules/views/views.module b/core/modules/views/views.module
index 13bec4d13e..c22b18c71f 100644
--- a/core/modules/views/views.module
+++ b/core/modules/views/views.module
@@ -68,6 +68,9 @@ function views_views_pre_render($view) {
         ],
       ],
     ];
+    if ($view->exposed_widgets) {
+      $view->element['#attached']['drupalSettings']['views']['ajaxViews']['views_dom_id:' . $view->dom_id]['view_html_id'] = $view->exposed_widgets['#id'];
+    }
     $view->element['#attached']['library'][] = 'views/views.ajax';
   }
 
