Trying to render an array of items with the drupal_add_html_head function I have a preprocess_html function that gets an array of google fonts and adds them as an html class. I have it partially working but if say I have three fonts, only the last one gets into &lt;html class=""&gt; element. Here is what I have so far:

if ($families) {
   foreach ($families as $fontString) {
   $fontclass = preg_replace('/[^\d\w]+/', '-', strtolower($fontString));

   $element = array(
     '#tag' =&gt; 'html',
     '#attributes' =&gt; array(
     'class' =&gt; $fontclass,
    ),
   );
   drupal_add_html_head($element, 'google_fonts');
  }
}


In the example above, I have these fonts in my site:


Montserrat
Actor
Pathway Gothic One


... but only the last one renders in my html class as:

&lt;html class="pathway-gothic-one-regular"&gt;


If I do a dsm within my function:

dsm(drupal_get_html_head());


I see all three fonts print out in separate boxes as

&lt;html class="actor-regular" /&gt;
&lt;html class="montserrat-regular" /&gt;
&lt;html class="pathway-gothic-one-regular" /&gt;


so I think I am not getting something right here. 

Note, if I change my code to a body class array, it works as expected. e.g.

   if ($families) {
          foreach ($families as $fontString) {
            $vars['classes_array'][] = preg_replace('/[^\d\w]+/', '-', strtolower($fontString));
          }
        }


yields:

&lt;body class="actor-regular montserrat-regular pathway-gothic-one-regular"&gt;


From a build standpoint, I'd like to keep these classes one level higher than body so that's why I'd like them to be in &lt;html class=""&gt;.
if ($families) {
    $element = array(
        '#tag' =&gt; 'html',
    );
    foreach ($families as $fontString) {
        $fontclass = preg_replace('/[^\d\w]+/', '-', strtolower($fontString));
        $element['#attributes'][class'][] = $fontclass;
    }
    drupal_add_html_head($element, 'google_fonts');
}