4 September 2023

In HTML, you should use the role="button" attribute when you want to indicate that an element on your web page acts like a button if it's not a traditional HTML element. This is particularly important for accessibility purposes, as it helps screen readers and assistive technologies understand the interactive nature of the element. Button should be everything else other than links. For example link that opens modal window, link that expands accordion, sort links, etc.

Source code viewer
  1. <div role="button" tabindex="-1" onclick="performAction()">Click me</div>
  2.  
  3. <a href="#" role="button" onclick="performAction()">Click me</a>
Programming Language: HTML