diff --git a/includes/common.inc b/includes/common.inc
index 20890f6..2a81696 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -3872,6 +3872,12 @@ function drupal_delete_file_if_stale($uri) {
  *   The cleaned identifier.
  */
 function drupal_clean_css_identifier($identifier, $filter = array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '')) {
+  // Preserve BEM-style double-underscores depending on custom setting.
+  $preserve_css_double_underscores = variable_get('preserve_css_double_underscores', FALSE);
+  if ($preserve_css_double_underscores) {
+    $filter['__'] = '__';
+  }
+
   // By default, we filter using Drupal's coding standards.
   $identifier = strtr($identifier, $filter);
 
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index bf85576..e91ce05 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -888,6 +888,10 @@ class DrupalHTMLIdentifierTestCase extends DrupalUnitTestCase {
 
     // Verify that invalid characters (including non-breaking space) are stripped from the identifier.
     $this->assertIdentical(drupal_clean_css_identifier('invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', array()), 'invalididentifier', 'Strip invalid characters.');
+
+    // Verify that double underscores are not stripped from the identifier.
+    $identifier = 'css__identifier__with__double__underscores';
+    $this->assertIdentical(drupal_clean_css_identifier($identifier), $identifier, 'Verify double underscores pass through.');
   }
 
   /**
