Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
Is adding tabindex="-1" to current menu item a good accessibility practice?

This is a basic navigation set up, using JavaScript to add the "current" class to a navigation link based on the current page's url.

To aid screen reader users, the script also adds aria-current="page" on the current link item.

In a further attempt at improving accessibility, I added tabindex="-1" to the current link item (see last line of script) . If users tab through the menu they will skip over the current link.

Is using tabindex in this way useful to screen readers, or more generally, an accessibility enhancement?

JS

window.addEventListener("DOMContentLoaded", () => {
  let url_pathname = window.location.pathname

  const link = document.querySelectorAll(".link")

  link.forEach(linkCurrentItem => {
    /* 
        A bit repetitious, but I wanted home page link to be just '/' 
        in the html. 

        If you have '/index.html' in the html then you can comment out
        the first if statement and edit the second like so:

        if (url_pathname === linkCurrentItem.getAttribute("href")) {
            ...
        }
    */
    if (url_pathname === linkCurrentItem.getAttribute("href", "/")) {
      linkCurrentItem.classList.add("current")
    }
    if (
      url_pathname === linkCurrentItem.getAttribute("href") &&
      url_pathname !== linkCurrentItem.getAttribute("href", "/")
    ) {
      linkCurrentItem.classList.add("current")
    }

    /* For screen readers */
    if (url_pathname === linkCurrentItem.getAttribute("href")) {
      linkCurrentItem.setAttribute("aria-current", "page")
  

      // IS ADDING tabindex="-1" A GOOD IDEA?
      linkCurrentItem.setAttribute("tabindex", "-1")
    }
  })
})

CSS

.link,
.link:visited {
    color: blue;
    text-decoration: none;
    font-weight: 400;
    font-size: 100%;
}

.current,
.current:visited {
    color: black;
    font-weight: 900;
    font-size: 125%;
    cursor: default;
}

HTML

<nav aria-label="main menu">
  <ul>
    <li><a class="link" href="/">Home</a></li>
    <li><a class="link" href="/projects.html">Projects</a></li>
    <li><a class="link" href="/blog.html">Blog</a></li>
    <li><a class="link" href="/about.html">About</a></li>
    <li><a class="link" href="/contact.html">Contact</a></li>
  </ul>
</nav>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I do not often answer with opinion but unfortunately there is no guidance as to how to do this as part of WCAG etc.

So instead I will just answer whether this enhances accessibility or not.

Is using tabindex in this way useful to screen readers, or more generally, an accessibility enhancement?

There aren't many circumstances where this would improve accessibility. You already added aria-current to indicate this is the current page so you have done the best thing there.

Negative impacts

Removing the page link from the focus order could be confusing for people who use assistive tech who have developed muscle memory on your site, however.

Let's say I want to get to the "about" page. If I visit regularly then I know that is 4 tab stops from the start of the navigation section. But if I am on the "projects" page and hit tab 4 times I would end up at the "contact" page as you have removed the projects page from the tab order.

Or what if a screen reader user did decide to use the Tab key to navigate (uncommon but not unheard of) then they would never hear your current page announcement in the navigation, despite adding the correct WAI-ARIA attribute to identify it.

They are only minor considerations though, nothing that makes the site inaccessible as such.

Enhancing Accessibility

So I suppose the only other question is does it have any accessibility benefits?

As far as I can see it doesn't.

It could save a tab stop on a page I suppose so might be a slightly quicker experience for repeat visitors...but that is really stretching!

Conclusion

I think the answer would be not to do this. The odds of you making a mistake in your JavaScript and accidentally making links unfocusable is high, if your JS is delayed or breaks then the tab order would be inconsistent etc.

As it doesn't really add anything but could potentially reduce accessibility for some people (albeit edge cases) I would say to not do it.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda