diff --git a/core/lib/Drupal/Component/Utility/Html.php b/core/lib/Drupal/Component/Utility/Html.php
index a775cdb..9e8e813 100644
--- a/core/lib/Drupal/Component/Utility/Html.php
+++ b/core/lib/Drupal/Component/Utility/Html.php
@@ -78,12 +78,23 @@ public static function getClass($class) {
   public static function cleanCssIdentifier($identifier, array $filter = array(
     ' ' => '-',
     '_' => '-',
-    '__' => '__',
     '/' => '-',
     '[' => '-',
-    ']' => ''
+    ']' => '',
   )) {
-    $identifier = strtr($identifier, $filter);
+    // We could also use strtr() here but its much slower than str_replace(). In
+    // order to keep '__' to stay '__' we first replace it with a different
+    // placeholder after checking that it is not defined as a filter.
+    $double_underscore_replacements = 0;
+    if (!isset($filter['__'])) {
+      $identifier = str_replace('__', '##', $identifier, $double_underscore_replacements);
+    }
+    $identifier = str_replace(array_keys($filter), array_values($filter), $identifier);
+    // Replace temporary placeholder '##' with '__' only if the original $identifier contained '__'.
+    if ($double_underscore_replacements > 0) {
+      $identifier = str_replace('##', '__', $identifier);
+    }
+
     // Valid characters in a CSS identifier are:
     // - the hyphen (U+002D)
     // - a-z (U+0030 - U+0039)
diff --git a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
index 28a2846..bca2623 100644
--- a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
@@ -79,7 +79,9 @@ public function providerTestCleanCssIdentifier() {
       // replaced.
       array('__cssidentifier', '-1cssidentifier', array()),
       // Verify that an identifier starting with two hyphens is replaced.
-      array('__cssidentifier', '--cssidentifier', array())
+      array('__cssidentifier', '--cssidentifier', array()),
+      // Verify that passing double underscores as a filter is processed.
+      array('_cssidentifier', '__cssidentifier',  array('__' => '_')),
     );
   }
 
