I am working on a drupal 8 project. I am building menus from drupal. My menu would be like the following structure:


--child 1

--child 2

--child 3

when i go to a page which is child 3, and the menu will also appear on that page. i would like to set active class on both child 3 and also parent. Is there any way to do so? Thanks.

1 Answer 1


That happens automatically, at least by default for themes inheriting from Classy. See https://api.drupal.org/api/drupal/core%21themes%21classy%21templates%21navigation%21menu.html.twig/8:

    set classes = [
      item.is_expanded ? 'menu-item--expanded',
      item.is_collapsed ? 'menu-item--collapsed',
      item.in_active_trail ? 'menu-item--active-trail',
  <li{{ item.attributes.addClass(classes) }}>

So, make sure you are inheriting from Classy (recommended) or duplicate some of this logic in your theme.

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.