In Drupal 8 is it safe to manually add a class attribute to the HTML element in the theme's html.html.twig file?

<html{{ html_attributes }} class="no-js">

Its working fine for me but I don't know if there are some instances where Drupal would want to add a class as part of html_attributes? If so then presumably my output would be this:

<html class="drupals-class" class="no-js">

1 Answer 1


You should use .addclass():

<html{{ html_attributes.addClass('no-js') }}>

That would prevent the output in the example from your question and the result will be:

<html class="drupals-class no-js">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.