How to add class in li element (for page where I am) in menu for drupal 8
To add active class to &lt;li&gt; need to add the following code in your .theme file and menu.html.twig

In .theme file add this

function themename_preprocess_menu(&amp;$variables, $hook) {
  if ($hook == 'menu__main') { // If it is not working replace "main__menu" with "menu"

    // Get the current path.
    $current_path = \Drupal::request()-&gt;getRequestUri();
    $items = $variables['items'];
    foreach ($items as $key =&gt; $item) {
      // If path is current_path, set active to li.
      if ($item['url']-&gt;toString() == $current_path) {
      // Add active link.
      $variables['items'][$key]['attributes']['class'] = 'active';
      }
    }
  }
}


In menu.html.twig replace your &lt;li&gt; with below line.

replace this line

{{ link(item.title, item.url) }}


by

&lt;li {{ item.attributes }} &gt;&lt;a  href="{{ item.url }}"  {{ item.attributes }} &gt; {{ item.title }}&lt;/a&gt;&lt;/li&gt;