In HTML5, this is very simple. Just omit the href
attribute.
From MDN on the a tag href attribute:
href
This was the single required attribute for anchors defining a hypertext source link, but is no longer required in HTML5.
What about the hand cursor on hover?
The default styles for a browser may not change the cursor to a pointer, for a
tags with no href
. You can universally change this with the following CSS.
a {
cursor: pointer;
}
<a>Do Nothing</a>
However it's probably better to be more-selective about it, and apply it to only the elements you intend to add event handlers to.
What about making it tab-focusable?
Just add tabindex="0"
to the element.
<a tabindex="0">Do Nothing</a>
Does it makes sense to use an a
tag without a link?
Usually no, it's probably better to use a button
element instead, and style it with CSS. But whatever you use, avoid using an arbitrary element like div
when possible, as this is not semantic at all.