Adding classes to menu items to signify what level they are How can I add classes to the &lt;a&gt; or &lt;li&gt; tags of the main menu to signify which level they are in the menu hierarchy (e.g. "level-1", "level-2", etc.)? The code below shows the first link has 3 sublinks (dropdown):

&lt;ul class="menu"&gt;
  &lt;li class="first expanded"&gt;
    &lt;a class="level-1" href="#" title=""&gt;Top link&lt;/a&gt;
    &lt;ul class="menu"&gt;
      &lt;li class="first leaf"&gt;&lt;a class="level-2" href="#"&gt;Dropdown 1&lt;/a&gt;&lt;/li&gt;
      &lt;li class="leaf"&gt;&lt;a class="level-2" href="#"&gt;Dropdown 2&lt;/a&gt;&lt;/li&gt;
      &lt;li class="last leaf"&gt;&lt;a class="level-2" href="#"&gt;Dropdown 3&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li class="last leaf"&gt;
    &lt;a class="level-1" href="#" title=""&gt;Another top link&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;
You can use theme_menu_link() in Drupal 7.

function MYTHEME_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = ''; 

  $element['#attributes']['class'][] = 'depth-' . $element['#original_link']['depth'];

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '&lt;li' . drupal_attributes($element['#attributes']) . '&gt;' . $output . $sub_menu . "&lt;/li&gt;\n";
}


Here I added:

$element['#attributes']['class'][] = 'depth-' . $element['#original_link']['depth'];


Which will provide a class on the list item with the menu depth.