By using the correct semantic HTML elements we can make use of built-in keyboard interactivity features.
The most commonly used tags are:
<a>
tag for making links. We can select the link using the Tab
key and then open it using Return
key. We can open the link in a new tab using Cmd + Shift + Return
. The Chrome, Edge, and Brave browser support this shortcut.
<button>
tag for making buttons. We can select the button using the Tab
key. Then we can click the button using the Space
or Return
key.
<select>
tag for adding dropdowns. We can use the Tab
or Shift
key to go to the next and previous options in the dropdown. We can use the Space
or Return
key to select an option.
<input>
and <textarea>
can be used to add input fields. We can select them using the Tab
key.
Since the alternative is to add your event listeners, we highly recommend using semantic HTML tags like the one shown above.