How to add class in li element (for page where I am) in menu for drupal 8 I would like to add class in li element in menu for drupal 8 for page where I am. For example if i am on page Start, that li have active class. Or If I am on Join page that li element for join have active class.

&lt;ul class=""&gt;
&lt;li class="active"&gt;&lt;a href="#" &gt;START&lt;/a&gt;&lt;/li&gt;
&lt;li class=""&gt;&lt;a href="#" &gt;About&lt;/a&gt;&lt;/li&gt;
&lt;li class=""&gt;&lt;a href="#" &gt;join&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


So, How to ask if li is active or no?

{% for item in items %}
  {% if item=SOMETHING %}
    &lt;li class="active"&gt;
      &lt;a  href="{{ item.url }}"&gt;{{ item.title }}&lt;/a&gt;
    &lt;/li&gt;
  {% else %}
    &lt;li &gt;
      &lt;a  href="{{ item.url }}"&gt;{{ item.title }}&lt;/a&gt;
    &lt;/li&gt;
{% endfor %}
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;